diff options
author | Joe Perches <joe@perches.com> | 2015-03-25 19:54:25 (GMT) |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-03-26 12:16:19 (GMT) |
commit | 031366ea65495f787eb792a135f51c093d75a197 (patch) | |
tree | 21b523d33f37b7d66cfcf798cb3ba43be8e1cc61 /drivers/staging/rts5208/sd.c | |
parent | da3c8deef6b392cfe9d19645de2fec9fc2005522 (diff) | |
download | linux-031366ea65495f787eb792a135f51c093d75a197.tar.xz |
staging: rts5208: Remove TRACE_RET and TRACE_GOTO macros
Remove these flow hiding macros.
Miscellanea:
o Add a macro and function to replace a large inline
o Simplify #includes
o Add trace.c and update Makefile
o Remove static inline filename function and use kbasename instead
This reduces object size quite a lot: ~350KB (x86-64 allyesconfig)
$ size drivers/staging/rts5208/built-in.o*
text data bss dec hex filename
248385 36728 77888 363001 589f9 drivers/staging/rts5208/built-in.o.new
506691 83352 115896 705939 ac593 drivers/staging/rts5208/built-in.o.old
Done via coccinelle script and some typing.
@@
expression chip;
expression ret;
@@
- TRACE_RET(chip, ret);
+ rtsx_trace(chip);
+ return ret;
@@
expression chip;
identifier label;
@@
- TRACE_GOTO(chip, label);
+ rtsx_trace(chip);
+ goto label;
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/rts5208/sd.c')
-rw-r--r-- | drivers/staging/rts5208/sd.c | 1389 |
1 files changed, 924 insertions, 465 deletions
diff --git a/drivers/staging/rts5208/sd.c b/drivers/staging/rts5208/sd.c index a03cbe9..0eee676 100644 --- a/drivers/staging/rts5208/sd.c +++ b/drivers/staging/rts5208/sd.c @@ -25,9 +25,6 @@ #include <linux/sched.h> #include "rtsx.h" -#include "rtsx_transport.h" -#include "rtsx_scsi.h" -#include "rtsx_card.h" #include "sd.h" #define SD_MAX_RETRY_COUNT 3 @@ -114,7 +111,8 @@ static int sd_check_data0_status(struct rtsx_chip *chip) if (!(stat & SD_DAT0_STATUS)) { sd_set_err_code(chip, SD_BUSY); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -187,7 +185,8 @@ RTY_SEND_CMD: retval = sd_check_data0_status(chip); if (retval != STATUS_SUCCESS) { rtsx_clear_sd_error(chip); - TRACE_RET(chip, retval); + rtsx_trace(chip); + return retval; } } else { sd_set_err_code(chip, SD_TO_ERR); @@ -198,7 +197,8 @@ RTY_SEND_CMD: } rtsx_clear_sd_error(chip); - TRACE_RET(chip, retval); + rtsx_trace(chip); + return retval; } if (rsp_type == SD_RSP_TYPE_R0) @@ -208,14 +208,16 @@ RTY_SEND_CMD: if ((ptr[0] & 0xC0) != 0) { sd_set_err_code(chip, SD_STS_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (!(rsp_type & SD_NO_CHECK_CRC7)) { if (ptr[stat_idx] & SD_CRC7_ERR) { if (cmd_idx == WRITE_MULTIPLE_BLOCK) { sd_set_err_code(chip, SD_CRC_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (rty_cnt < SD_MAX_RETRY_COUNT) { wait_timeout(20); @@ -223,7 +225,8 @@ RTY_SEND_CMD: goto RTY_SEND_CMD; } else { sd_set_err_code(chip, SD_CRC_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } } @@ -232,8 +235,10 @@ RTY_SEND_CMD: if ((cmd_idx != SEND_RELATIVE_ADDR) && (cmd_idx != SEND_IF_COND)) { if (cmd_idx != STOP_TRANSMISSION) { - if (ptr[1] & 0x80) - TRACE_RET(chip, STATUS_FAIL); + if (ptr[1] & 0x80) { + rtsx_trace(chip); + return STATUS_FAIL; + } } #ifdef SUPPORT_SD_LOCK if (ptr[1] & 0x7D) @@ -243,17 +248,20 @@ RTY_SEND_CMD: { dev_dbg(rtsx_dev(chip), "ptr[1]: 0x%02x\n", ptr[1]); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (ptr[2] & 0xFF) { dev_dbg(rtsx_dev(chip), "ptr[2]: 0x%02x\n", ptr[2]); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (ptr[3] & 0x80) { dev_dbg(rtsx_dev(chip), "ptr[3]: 0x%02x\n", ptr[3]); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (ptr[3] & 0x01) sd_card->sd_data_buf_ready = 1; @@ -282,8 +290,10 @@ static int sd_read_data(struct rtsx_chip *chip, if (!buf) buf_len = 0; - if (buf_len > 512) - TRACE_RET(chip, STATUS_FAIL); + if (buf_len > 512) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -323,13 +333,16 @@ static int sd_read_data(struct rtsx_chip *chip, SD_RSP_TYPE_R1, NULL, 0); } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (buf && buf_len) { retval = rtsx_read_ppbuf(chip, buf, buf_len); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -350,13 +363,16 @@ static int sd_write_data(struct rtsx_chip *chip, u8 trans_mode, if (buf_len > 512) { /* This function can't write data more than one page */ - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (buf && buf_len) { retval = rtsx_write_ppbuf(chip, buf, buf_len); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } rtsx_init_cmd(chip); @@ -395,7 +411,8 @@ static int sd_write_data(struct rtsx_chip *chip, u8 trans_mode, sd_card->sd_addr, SD_RSP_TYPE_R1, NULL, 0); } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -412,7 +429,8 @@ static int sd_check_csd(struct rtsx_chip *chip, char check_wp) for (i = 0; i < 6; i++) { if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) { sd_set_err_code(chip, SD_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = sd_send_cmd_get_rsp(chip, SEND_CSD, sd_card->sd_addr, @@ -421,8 +439,10 @@ static int sd_check_csd(struct rtsx_chip *chip, char check_wp) break; } - if (i == 6) - TRACE_RET(chip, STATUS_FAIL); + if (i == 6) { + rtsx_trace(chip); + return STATUS_FAIL; + } memcpy(sd_card->raw_csd, rsp + 1, 15); @@ -464,10 +484,12 @@ static int sd_check_csd(struct rtsx_chip *chip, char check_wp) else sd_card->sd_clock = CLK_20; } else { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } else { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (CHK_MMC_SECTOR_MODE(sd_card)) { @@ -606,14 +628,18 @@ static int sd_set_init_para(struct rtsx_chip *chip) int retval; retval = sd_set_sample_push_timing(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } sd_choose_proper_clock(chip); retval = switch_clock(chip, sd_card->sd_clock); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -636,8 +662,10 @@ int sd_select_card(struct rtsx_chip *chip, int select) } retval = sd_send_cmd_get_rsp(chip, cmd_idx, addr, cmd_type, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -651,8 +679,10 @@ static int sd_update_lock_status(struct rtsx_chip *chip) retval = sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr, SD_RSP_TYPE_R1, rsp, 5); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (rsp[1] & 0x02) sd_card->sd_lock_status |= SD_LOCKED; @@ -662,8 +692,10 @@ static int sd_update_lock_status(struct rtsx_chip *chip) dev_dbg(rtsx_dev(chip), "sd_card->sd_lock_status = 0x%x\n", sd_card->sd_lock_status); - if (rsp[1] & 0x01) - TRACE_RET(chip, STATUS_FAIL); + if (rsp[1] & 0x01) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -680,15 +712,18 @@ static int sd_wait_state_data_ready(struct rtsx_chip *chip, u8 state, retval = sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr, SD_RSP_TYPE_R1, rsp, 5); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (((rsp[3] & 0x1E) == state) && ((rsp[3] & 0x01) == data_ready)) return STATUS_SUCCESS; } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } static int sd_change_bank_voltage(struct rtsx_chip *chip, u8 voltage) @@ -700,8 +735,10 @@ static int sd_change_bank_voltage(struct rtsx_chip *chip, u8 voltage) retval = rtsx_write_phy_register(chip, 0x08, 0x4FC0 | chip->phy_voltage); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else { RTSX_WRITE_REG(chip, SD_PAD_CTL, SD_IO_USING_1V8, 0); } @@ -710,14 +747,17 @@ static int sd_change_bank_voltage(struct rtsx_chip *chip, u8 voltage) retval = rtsx_write_phy_register(chip, 0x08, 0x4C40 | chip->phy_voltage); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else { RTSX_WRITE_REG(chip, SD_PAD_CTL, SD_IO_USING_1V8, SD_IO_USING_1V8); } } else { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -733,21 +773,26 @@ static int sd_voltage_switch(struct rtsx_chip *chip) retval = sd_send_cmd_get_rsp(chip, VOLTAGE_SWITCH, 0, SD_RSP_TYPE_R1, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } udelay(chip->sd_voltage_switch_delay); RTSX_READ_REG(chip, SD_BUS_STAT, &stat); if (stat & (SD_CMD_STATUS | SD_DAT3_STATUS | SD_DAT2_STATUS | SD_DAT1_STATUS | SD_DAT0_STATUS)) { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } RTSX_WRITE_REG(chip, SD_BUS_STAT, 0xFF, SD_CLK_FORCE_STOP); retval = sd_change_bank_voltage(chip, SD_IO_1V8); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } wait_timeout(50); @@ -763,7 +808,8 @@ static int sd_voltage_switch(struct rtsx_chip *chip) rtsx_write_register(chip, SD_BUS_STAT, SD_CLK_TOGGLE_EN | SD_CLK_FORCE_STOP, 0); rtsx_write_register(chip, CARD_CLK_EN, 0xFF, 0); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } RTSX_WRITE_REG(chip, SD_BUS_STAT, SD_CLK_TOGGLE_EN | SD_CLK_FORCE_STOP, @@ -839,15 +885,21 @@ static int sd_change_phase(struct rtsx_chip *chip, u8 sample_point, u8 tune_dir) rtsx_add_cmd(chip, CHECK_REG_CMD, SD_DCMPS_CTL, DCMPS_CHANGE_DONE, DCMPS_CHANGE_DONE); retval = rtsx_send_cmd(chip, SD_CARD, 100); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, Fail); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto Fail; + } val = *rtsx_get_cmd_data(chip); - if (val & DCMPS_ERROR) - TRACE_GOTO(chip, Fail); + if (val & DCMPS_ERROR) { + rtsx_trace(chip); + goto Fail; + } - if ((val & DCMPS_CURRENT_PHASE) != sample_point) - TRACE_GOTO(chip, Fail); + if ((val & DCMPS_CURRENT_PHASE) != sample_point) { + rtsx_trace(chip); + goto Fail; + } RTSX_WRITE_REG(chip, SD_DCMPS_CTL, DCMPS_CHANGE, 0); if (ddr_rx) @@ -883,8 +935,10 @@ static int sd_check_spec(struct rtsx_chip *chip, u8 bus_width) retval = sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr, SD_RSP_TYPE_R1, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } cmd[0] = 0x40 | SEND_SCR; cmd[1] = 0; @@ -896,13 +950,16 @@ static int sd_check_spec(struct rtsx_chip *chip, u8 bus_width) buf, 8, 250); if (retval != STATUS_SUCCESS) { rtsx_clear_sd_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } memcpy(sd_card->raw_scr, buf, 8); - if ((buf[0] & 0x0F) == 0) - TRACE_RET(chip, STATUS_FAIL); + if ((buf[0] & 0x0F) == 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -944,7 +1001,8 @@ static int sd_query_switch_result(struct rtsx_chip *chip, u8 func_group, break; default: - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } else if (func_group == SD_FUNC_GROUP_3) { support_offset = FUNCTION_GROUP3_SUPPORT_OFFSET; @@ -971,7 +1029,8 @@ static int sd_query_switch_result(struct rtsx_chip *chip, u8 func_group, break; default: - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } else if (func_group == SD_FUNC_GROUP_4) { support_offset = FUNCTION_GROUP4_SUPPORT_OFFSET; @@ -998,23 +1057,27 @@ static int sd_query_switch_result(struct rtsx_chip *chip, u8 func_group, break; default: - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } else { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (func_group == SD_FUNC_GROUP_1) { if (!(buf[support_offset] & support_mask) || ((buf[query_switch_offset] & 0x0F) != query_switch)) { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } /* Check 'Busy Status' */ if ((buf[DATA_STRUCTURE_VER_OFFSET] == 0x01) && ((buf[check_busy_offset] & switch_busy) == switch_busy)) { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -1056,7 +1119,8 @@ static int sd_check_switch_mode(struct rtsx_chip *chip, u8 mode, buf, 64, 250); if (retval != STATUS_SUCCESS) { rtsx_clear_sd_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } dev_dbg(rtsx_dev(chip), "%*ph\n", 64, buf); @@ -1083,13 +1147,17 @@ static int sd_check_switch_mode(struct rtsx_chip *chip, u8 mode, dev_dbg(rtsx_dev(chip), "Maximum current consumption: %dmA\n", cc); - if ((cc == 0) || (cc > 800)) - TRACE_RET(chip, STATUS_FAIL); + if ((cc == 0) || (cc > 800)) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sd_query_switch_result(chip, func_group, func_to_switch, buf, 64); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if ((cc > 400) || (func_to_switch > CURRENT_LIMIT_400)) { RTSX_WRITE_REG(chip, OCPPARA2, SD_OCP_THD_MASK, @@ -1126,7 +1194,8 @@ static int sd_check_switch(struct rtsx_chip *chip, for (i = 0; i < 3; i++) { if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) { sd_set_err_code(chip, SD_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = sd_check_switch_mode(chip, SD_CHECK_MODE, func_group, @@ -1144,7 +1213,8 @@ static int sd_check_switch(struct rtsx_chip *chip, RTSX_READ_REG(chip, SD_STAT1, &stat); if (stat & SD_CRC16_ERR) { dev_dbg(rtsx_dev(chip), "SD CRC16 error when switching mode\n"); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1154,8 +1224,10 @@ static int sd_check_switch(struct rtsx_chip *chip, wait_timeout(20); } - if (!switch_good) - TRACE_RET(chip, STATUS_FAIL); + if (!switch_good) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -1170,8 +1242,10 @@ static int sd_switch_function(struct rtsx_chip *chip, u8 bus_width) /* Get supported functions */ retval = sd_check_switch_mode(chip, SD_CHECK_MODE, NO_ARGUMENT, NO_ARGUMENT, bus_width); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } sd_card->func_group1_mask &= ~(sd_card->sd_switch_fail); @@ -1239,7 +1313,8 @@ static int sd_switch_function(struct rtsx_chip *chip, u8 bus_width) sd_card->sd_switch_fail = SDR104_SUPPORT_MASK | DDR50_SUPPORT_MASK | SDR50_SUPPORT_MASK; } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (func_to_switch == SDR104_SUPPORT) @@ -1255,8 +1330,10 @@ static int sd_switch_function(struct rtsx_chip *chip, u8 bus_width) if (CHK_SD_DDR50(sd_card)) { RTSX_WRITE_REG(chip, SD_PUSH_POINT_CTL, 0x06, 0x04); retval = sd_set_sample_push_timing(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } if (!func_to_switch || (func_to_switch == HS_SUPPORT)) { @@ -1310,8 +1387,10 @@ static int sd_switch_function(struct rtsx_chip *chip, u8 bus_width) retval = sd_check_switch(chip, SD_FUNC_GROUP_4, func_to_switch, bus_width); if (retval != STATUS_SUCCESS) { - if (sd_check_err_code(chip, SD_NO_CARD)) - TRACE_RET(chip, STATUS_FAIL); + if (sd_check_err_code(chip, SD_NO_CARD)) { + rtsx_trace(chip); + return STATUS_FAIL; + } } dev_dbg(rtsx_dev(chip), "Switch current limit finished! (%d)\n", retval); @@ -1348,8 +1427,10 @@ static int sd_sdr_tuning_rx_cmd(struct rtsx_chip *chip, u8 sample_point) u8 cmd[5]; retval = sd_change_phase(chip, sample_point, TUNE_RX); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } cmd[0] = 0x40 | SEND_TUNING_PATTERN; cmd[1] = 0; @@ -1363,7 +1444,8 @@ static int sd_sdr_tuning_rx_cmd(struct rtsx_chip *chip, u8 sample_point) (void)sd_wait_data_idle(chip); rtsx_clear_sd_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -1376,15 +1458,19 @@ static int sd_ddr_tuning_rx_cmd(struct rtsx_chip *chip, u8 sample_point) u8 cmd[5]; retval = sd_change_phase(chip, sample_point, TUNE_RX); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } dev_dbg(rtsx_dev(chip), "sd ddr tuning rx\n"); retval = sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr, SD_RSP_TYPE_R1, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } cmd[0] = 0x40 | SD_STATUS; cmd[1] = 0; @@ -1398,7 +1484,8 @@ static int sd_ddr_tuning_rx_cmd(struct rtsx_chip *chip, u8 sample_point) (void)sd_wait_data_idle(chip); rtsx_clear_sd_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -1418,8 +1505,10 @@ static int mmc_ddr_tunning_rx_cmd(struct rtsx_chip *chip, u8 sample_point) bus_width = SD_BUS_WIDTH_1; retval = sd_change_phase(chip, sample_point, TUNE_RX); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } dev_dbg(rtsx_dev(chip), "mmc ddr tuning rx\n"); @@ -1435,7 +1524,8 @@ static int mmc_ddr_tunning_rx_cmd(struct rtsx_chip *chip, u8 sample_point) (void)sd_wait_data_idle(chip); rtsx_clear_sd_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -1447,8 +1537,10 @@ static int sd_sdr_tuning_tx_cmd(struct rtsx_chip *chip, u8 sample_point) int retval; retval = sd_change_phase(chip, sample_point, TUNE_TX); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_WRITE_REG(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN, SD_RSP_80CLK_TIMEOUT_EN); @@ -1459,7 +1551,8 @@ static int sd_sdr_tuning_tx_cmd(struct rtsx_chip *chip, u8 sample_point) if (sd_check_err_code(chip, SD_RSP_TIMEOUT)) { rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN, 0); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1475,8 +1568,10 @@ static int sd_ddr_tuning_tx_cmd(struct rtsx_chip *chip, u8 sample_point) u8 cmd[5], bus_width; retval = sd_change_phase(chip, sample_point, TUNE_TX); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (CHK_SD(sd_card)) { bus_width = SD_BUS_WIDTH_4; @@ -1490,8 +1585,10 @@ static int sd_ddr_tuning_tx_cmd(struct rtsx_chip *chip, u8 sample_point) } retval = sd_wait_state_data_ready(chip, 0x08, 1, 1000); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_WRITE_REG(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN, SD_RSP_80CLK_TIMEOUT_EN); @@ -1507,7 +1604,8 @@ static int sd_ddr_tuning_tx_cmd(struct rtsx_chip *chip, u8 sample_point) if (retval != STATUS_SUCCESS) { rtsx_clear_sd_error(chip); rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN, 0); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } RTSX_WRITE_REG(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN, 0); @@ -1655,8 +1753,10 @@ static int sd_tuning_rx(struct rtsx_chip *chip) } else { if (CHK_MMC_DDR52(sd_card)) tuning_cmd = mmc_ddr_tunning_rx_cmd; - else - TRACE_RET(chip, STATUS_FAIL); + else { + rtsx_trace(chip); + return STATUS_FAIL; + } } for (i = 0; i < 3; i++) { @@ -1664,7 +1764,8 @@ static int sd_tuning_rx(struct rtsx_chip *chip) for (j = MAX_PHASE; j >= 0; j--) { if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) { sd_set_err_code(chip, SD_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = tuning_cmd(chip, (u8)j); @@ -1681,12 +1782,16 @@ static int sd_tuning_rx(struct rtsx_chip *chip) dev_dbg(rtsx_dev(chip), "RX phase_map = 0x%08x\n", phase_map); final_phase = sd_search_final_phase(chip, phase_map, TUNE_RX); - if (final_phase == 0xFF) - TRACE_RET(chip, STATUS_FAIL); + if (final_phase == 0xFF) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sd_change_phase(chip, final_phase, TUNE_RX); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -1708,7 +1813,8 @@ static int sd_ddr_pre_tuning_tx(struct rtsx_chip *chip) sd_set_err_code(chip, SD_NO_CARD); rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN, 0); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = sd_change_phase(chip, (u8)i, TUNE_TX); @@ -1729,12 +1835,16 @@ static int sd_ddr_pre_tuning_tx(struct rtsx_chip *chip) phase_map); final_phase = sd_search_final_phase(chip, phase_map, TUNE_TX); - if (final_phase == 0xFF) - TRACE_RET(chip, STATUS_FAIL); + if (final_phase == 0xFF) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sd_change_phase(chip, final_phase, TUNE_TX); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } dev_dbg(rtsx_dev(chip), "DDR TX pre tune phase: %d\n", (int)final_phase); @@ -1760,8 +1870,10 @@ static int sd_tuning_tx(struct rtsx_chip *chip) } else { if (CHK_MMC_DDR52(sd_card)) tuning_cmd = sd_ddr_tuning_tx_cmd; - else - TRACE_RET(chip, STATUS_FAIL); + else { + rtsx_trace(chip); + return STATUS_FAIL; + } } for (i = 0; i < 3; i++) { @@ -1771,7 +1883,8 @@ static int sd_tuning_tx(struct rtsx_chip *chip) sd_set_err_code(chip, SD_NO_CARD); rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN, 0); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = tuning_cmd(chip, (u8)j); @@ -1788,12 +1901,16 @@ static int sd_tuning_tx(struct rtsx_chip *chip) dev_dbg(rtsx_dev(chip), "TX phase_map = 0x%08x\n", phase_map); final_phase = sd_search_final_phase(chip, phase_map, TUNE_TX); - if (final_phase == 0xFF) - TRACE_RET(chip, STATUS_FAIL); + if (final_phase == 0xFF) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sd_change_phase(chip, final_phase, TUNE_TX); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -1803,12 +1920,16 @@ static int sd_sdr_tuning(struct rtsx_chip *chip) int retval; retval = sd_tuning_tx(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sd_tuning_rx(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -1819,23 +1940,31 @@ static int sd_ddr_tuning(struct rtsx_chip *chip) if (!(chip->sd_ctl & SD_DDR_TX_PHASE_SET_BY_USER)) { retval = sd_ddr_pre_tuning_tx(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else { retval = sd_change_phase(chip, (u8)chip->sd_ddr_tx_phase, TUNE_TX); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } retval = sd_tuning_rx(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (!(chip->sd_ctl & SD_DDR_TX_PHASE_SET_BY_USER)) { retval = sd_tuning_tx(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -1847,23 +1976,31 @@ static int mmc_ddr_tuning(struct rtsx_chip *chip) if (!(chip->sd_ctl & MMC_DDR_TX_PHASE_SET_BY_USER)) { retval = sd_ddr_pre_tuning_tx(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else { retval = sd_change_phase(chip, (u8)chip->mmc_ddr_tx_phase, TUNE_TX); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } retval = sd_tuning_rx(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (!(chip->sd_ctl & MMC_DDR_TX_PHASE_SET_BY_USER)) { retval = sd_tuning_tx(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -1876,12 +2013,16 @@ int sd_switch_clock(struct rtsx_chip *chip) int re_tuning = 0; retval = select_card(chip, SD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = switch_clock(chip, sd_card->sd_clock); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (re_tuning) { if (CHK_SD(sd_card)) { @@ -1894,8 +2035,10 @@ int sd_switch_clock(struct rtsx_chip *chip) retval = mmc_ddr_tuning(chip); } - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -1925,8 +2068,10 @@ static int sd_prepare_reset(struct rtsx_chip *chip) chip->sd_io = 0; retval = sd_set_init_para(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, retval); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return retval; + } RTSX_WRITE_REG(chip, REG_SD_CFG1, 0xFF, 0x40); @@ -1934,8 +2079,10 @@ static int sd_prepare_reset(struct rtsx_chip *chip) SD_STOP | SD_CLR_ERR); retval = select_card(chip, SD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -1999,8 +2146,10 @@ int sd_pull_ctl_enable(struct rtsx_chip *chip) } retval = rtsx_send_cmd(chip, SD_CARD, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -2010,20 +2159,26 @@ static int sd_init_power(struct rtsx_chip *chip) int retval; retval = sd_power_off_card3v3(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (!chip->ft2_fast_mode) wait_timeout(250); retval = enable_card_clock(chip, SD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (chip->asic_code) { retval = sd_pull_ctl_enable(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else { RTSX_WRITE_REG(chip, FPGA_PULL_CTL, FPGA_SD_PULL_CTL_BIT | 0x20, 0); @@ -2031,8 +2186,10 @@ static int sd_init_power(struct rtsx_chip *chip) if (!chip->ft2_fast_mode) { retval = card_power_on(chip, SD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } wait_timeout(260); @@ -2040,7 +2197,8 @@ static int sd_init_power(struct rtsx_chip *chip) if (chip->ocp_stat & (SD_OC_NOW | SD_OC_EVER)) { dev_dbg(rtsx_dev(chip), "Over current, OCPSTAT is 0x%x\n", chip->ocp_stat); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #endif } @@ -2086,7 +2244,8 @@ static int sd_read_lba0(struct rtsx_chip *chip) 5, 512, 1, bus_width, NULL, 0, 100); if (retval != STATUS_SUCCESS) { rtsx_clear_sd_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -2102,8 +2261,10 @@ static int sd_check_wp_state(struct rtsx_chip *chip) retval = sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr, SD_RSP_TYPE_R1, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } cmd[0] = 0x40 | SD_STATUS; cmd[1] = 0; @@ -2118,7 +2279,8 @@ static int sd_check_wp_state(struct rtsx_chip *chip) sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr, SD_RSP_TYPE_R1, NULL, 0); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } dev_dbg(rtsx_dev(chip), "ACMD13:\n"); @@ -2167,12 +2329,16 @@ Switch_Fail: #endif retval = sd_prepare_reset(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sd_dummy_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (CHK_SDIO_EXIST(chip) && !CHK_SDIO_IGNORED(chip) && try_sdio) { int rty_cnt = 0; @@ -2180,7 +2346,8 @@ Switch_Fail: for (; rty_cnt < chip->sdio_retry_cnt; rty_cnt++) { if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) { sd_set_err_code(chip, SD_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = sd_send_cmd_get_rsp(chip, IO_SEND_OP_COND, 0, @@ -2192,7 +2359,8 @@ Switch_Fail: dev_dbg(rtsx_dev(chip), "SD_IO card (Function number: %d)!\n", func_num); chip->sd_io = 1; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } break; @@ -2210,8 +2378,10 @@ Switch_Fail: RTY_SD_RST: retval = sd_send_cmd_get_rsp(chip, GO_IDLE_STATE, 0, SD_RSP_TYPE_R0, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } wait_timeout(20); @@ -2229,8 +2399,10 @@ RTY_SD_RST: retval = sd_send_cmd_get_rsp(chip, GO_IDLE_STATE, 0, SD_RSP_TYPE_R0, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } wait_timeout(20); } @@ -2241,14 +2413,17 @@ RTY_SD_RST: if (retval != STATUS_SUCCESS) { if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) { sd_set_err_code(chip, SD_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } j++; if (j < 3) goto RTY_SD_RST; - else - TRACE_RET(chip, STATUS_FAIL); + else { + rtsx_trace(chip); + return STATUS_FAIL; + } } retval = sd_send_cmd_get_rsp(chip, SD_APP_OP_COND, voltage, @@ -2257,16 +2432,20 @@ RTY_SD_RST: k++; if (k < 3) goto RTY_SD_RST; - else - TRACE_RET(chip, STATUS_FAIL); + else { + rtsx_trace(chip); + return STATUS_FAIL; + } } i++; wait_timeout(20); } while (!(rsp[1] & 0x80) && (i < 255)); - if (i == 255) - TRACE_RET(chip, STATUS_FAIL); + if (i == 255) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (hi_cap_flow) { if (rsp[1] & 0x40) @@ -2283,20 +2462,26 @@ RTY_SD_RST: if (support_1v8) { retval = sd_voltage_switch(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } retval = sd_send_cmd_get_rsp(chip, ALL_SEND_CID, 0, SD_RSP_TYPE_R2, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } for (i = 0; i < 3; i++) { retval = sd_send_cmd_get_rsp(chip, SEND_RELATIVE_ADDR, 0, SD_RSP_TYPE_R6, rsp, 5); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } sd_card->sd_addr = (u32)rsp[1] << 24; sd_card->sd_addr += (u32)rsp[2] << 16; @@ -2306,18 +2491,24 @@ RTY_SD_RST: } retval = sd_check_csd(chip, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sd_select_card(chip, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } #ifdef SUPPORT_SD_LOCK SD_UNLOCK_ENTRY: retval = sd_update_lock_status(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (sd_card->sd_lock_status & SD_LOCKED) { sd_card->sd_lock_status |= (SD_LOCK_1BIT_MODE | SD_PWD_EXIST); @@ -2329,24 +2520,32 @@ SD_UNLOCK_ENTRY: retval = sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr, SD_RSP_TYPE_R1, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sd_send_cmd_get_rsp(chip, SET_CLR_CARD_DETECT, 0, SD_RSP_TYPE_R1, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (support_1v8) { retval = sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr, SD_RSP_TYPE_R1, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sd_send_cmd_get_rsp(chip, SET_BUS_WIDTH, 2, SD_RSP_TYPE_R1, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } switch_bus_width = SD_BUS_WIDTH_4; } else { @@ -2355,12 +2554,16 @@ SD_UNLOCK_ENTRY: retval = sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, 0x200, SD_RSP_TYPE_R1, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sd_set_clock_divider(chip, SD_CLK_DIVIDE_0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (!(sd_card->raw_csd[4] & 0x40)) sd_dont_switch = true; @@ -2399,13 +2602,17 @@ SD_UNLOCK_ENTRY: if (!support_1v8) { retval = sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr, SD_RSP_TYPE_R1, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sd_send_cmd_get_rsp(chip, SET_BUS_WIDTH, 2, SD_RSP_TYPE_R1, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } #ifdef SUPPORT_SD_LOCK @@ -2419,8 +2626,10 @@ SD_UNLOCK_ENTRY: chip->sd30_drive_sel_1v8); retval = sd_set_init_para(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (CHK_SD_DDR50(sd_card)) retval = sd_ddr_tuning(chip); @@ -2429,11 +2638,14 @@ SD_UNLOCK_ENTRY: if (retval != STATUS_SUCCESS) { if (sd20_mode) { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } else { retval = sd_init_power(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } try_sdio = false; sd20_mode = true; @@ -2454,11 +2666,14 @@ SD_UNLOCK_ENTRY: retval = sd_read_lba0(chip); if (retval != STATUS_SUCCESS) { if (sd20_mode) { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } else { retval = sd_init_power(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } try_sdio = false; sd20_mode = true; @@ -2469,8 +2684,10 @@ SD_UNLOCK_ENTRY: } retval = sd_check_wp_state(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } chip->card_bus_width[chip->card2lun[SD_CARD]] = 4; @@ -2495,8 +2712,10 @@ static int mmc_test_switch_bus(struct rtsx_chip *chip, u8 width) retval = sd_send_cmd_get_rsp(chip, BUSTEST_W, 0, SD_RSP_TYPE_R1, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, SWITCH_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return SWITCH_FAIL; + } if (width == MMC_8BIT_BUS) { buf[0] = 0x55; @@ -2512,20 +2731,25 @@ static int mmc_test_switch_bus(struct rtsx_chip *chip, u8 width) } retval = rtsx_write_register(chip, REG_SD_CFG3, 0x02, 0x02); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, SWITCH_ERR); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return SWITCH_ERR; + } retval = sd_write_data(chip, SD_TM_AUTO_WRITE_3, NULL, 0, byte_cnt, 1, bus_width, buf, len, 100); if (retval != STATUS_SUCCESS) { rtsx_clear_sd_error(chip); rtsx_write_register(chip, REG_SD_CFG3, 0x02, 0); - TRACE_RET(chip, SWITCH_ERR); + rtsx_trace(chip); + return SWITCH_ERR; } retval = rtsx_write_register(chip, REG_SD_CFG3, 0x02, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, SWITCH_ERR); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return SWITCH_ERR; + } dev_dbg(rtsx_dev(chip), "SD/MMC CMD %d\n", BUSTEST_R); @@ -2560,7 +2784,8 @@ static int mmc_test_switch_bus(struct rtsx_chip *chip, u8 width) retval = rtsx_send_cmd(chip, SD_CARD, 100); if (retval < 0) { rtsx_clear_sd_error(chip); - TRACE_RET(chip, SWITCH_ERR); + rtsx_trace(chip); + return SWITCH_ERR; } ptr = rtsx_get_cmd_data(chip) + 1; @@ -2602,7 +2827,8 @@ static int mmc_test_switch_bus(struct rtsx_chip *chip, u8 width) } } - TRACE_RET(chip, SWITCH_FAIL); + rtsx_trace(chip); + return SWITCH_FAIL; } @@ -2653,14 +2879,16 @@ static int mmc_switch_timing_bus(struct rtsx_chip *chip, bool switch_ddr) sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr, SD_RSP_TYPE_R1, NULL, 0); } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } ptr = rtsx_get_cmd_data(chip); if (ptr[0] & SD_TRANSFER_ERR) { sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr, SD_RSP_TYPE_R1, NULL, 0); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (CHK_MMC_SECTOR_MODE(sd_card)) { @@ -2692,8 +2920,10 @@ static int mmc_switch_timing_bus(struct rtsx_chip *chip, bool switch_ddr) sd_choose_proper_clock(chip); retval = switch_clock(chip, sd_card->sd_clock); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } /* Test Bus Procedure */ retval = mmc_test_switch_bus(chip, MMC_8BIT_BUS); @@ -2715,10 +2945,12 @@ static int mmc_switch_timing_bus(struct rtsx_chip *chip, bool switch_ddr) CLR_MMC_8BIT(sd_card); CLR_MMC_4BIT(sd_card); } else { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } else { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -2741,21 +2973,26 @@ static int reset_mmc(struct rtsx_chip *chip) Switch_Fail: retval = sd_prepare_reset(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, retval); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return retval; + } SET_MMC(sd_card); RTY_MMC_RST: retval = sd_send_cmd_get_rsp(chip, GO_IDLE_STATE, 0, SD_RSP_TYPE_R0, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } do { if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) { sd_set_err_code(chip, SD_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = sd_send_cmd_get_rsp(chip, SEND_OP_COND, @@ -2769,7 +3006,8 @@ RTY_MMC_RST: sd_clr_err_code(chip); goto RTY_MMC_RST; } else { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } else { j++; @@ -2777,7 +3015,8 @@ RTY_MMC_RST: sd_clr_err_code(chip); goto RTY_MMC_RST; } else { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } } @@ -2786,8 +3025,10 @@ RTY_MMC_RST: i++; } while (!(rsp[1] & 0x80) && (i < 255)); - if (i == 255) - TRACE_RET(chip, STATUS_FAIL); + if (i == 255) { + rtsx_trace(chip); + return STATUS_FAIL; + } if ((rsp[1] & 0x60) == 0x40) SET_MMC_SECTOR_MODE(sd_card); @@ -2796,40 +3037,54 @@ RTY_MMC_RST: retval = sd_send_cmd_get_rsp(chip, ALL_SEND_CID, 0, SD_RSP_TYPE_R2, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } sd_card->sd_addr = 0x00100000; retval = sd_send_cmd_get_rsp(chip, SET_RELATIVE_ADDR, sd_card->sd_addr, SD_RSP_TYPE_R6, rsp, 5); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sd_check_csd(chip, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } spec_ver = (sd_card->raw_csd[0] & 0x3C) >> 2; retval = sd_select_card(chip, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, 0x200, SD_RSP_TYPE_R1, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } #ifdef SUPPORT_SD_LOCK MMC_UNLOCK_ENTRY: retval = sd_update_lock_status(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } #endif retval = sd_set_clock_divider(chip, SD_CLK_DIVIDE_0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } chip->card_bus_width[chip->card2lun[SD_CARD]] = 1; @@ -2839,29 +3094,39 @@ MMC_UNLOCK_ENTRY: retval = mmc_switch_timing_bus(chip, switch_ddr); if (retval != STATUS_SUCCESS) { retval = sd_init_power(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } sd_card->mmc_dont_switch_bus = 1; - TRACE_GOTO(chip, Switch_Fail); + rtsx_trace(chip); + goto Switch_Fail; } } - if (CHK_MMC_SECTOR_MODE(sd_card) && (sd_card->capacity == 0)) - TRACE_RET(chip, STATUS_FAIL); + if (CHK_MMC_SECTOR_MODE(sd_card) && (sd_card->capacity == 0)) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (switch_ddr && CHK_MMC_DDR52(sd_card)) { retval = sd_set_init_para(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = mmc_ddr_tuning(chip); if (retval != STATUS_SUCCESS) { retval = sd_init_power(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } switch_ddr = false; - TRACE_GOTO(chip, Switch_Fail); + rtsx_trace(chip); + goto Switch_Fail; } retval = sd_wait_state_data_ready(chip, 0x08, 1, 1000); @@ -2869,11 +3134,14 @@ MMC_UNLOCK_ENTRY: retval = sd_read_lba0(chip); if (retval != STATUS_SUCCESS) { retval = sd_init_power(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } switch_ddr = false; - TRACE_GOTO(chip, Switch_Fail); + rtsx_trace(chip); + goto Switch_Fail; } } } @@ -2904,62 +3172,84 @@ int reset_sd_card(struct rtsx_chip *chip) chip->capacity[chip->card2lun[SD_CARD]] = 0; retval = enable_card_clock(chip, SD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (chip->ignore_sd && CHK_SDIO_EXIST(chip) && !CHK_SDIO_IGNORED(chip)) { if (chip->asic_code) { retval = sd_pull_ctl_enable(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else { retval = rtsx_write_register(chip, FPGA_PULL_CTL, FPGA_SD_PULL_CTL_BIT | 0x20, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } retval = card_share_mode(chip, SD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } chip->sd_io = 1; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = sd_init_power(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (chip->sd_ctl & RESET_MMC_FIRST) { retval = reset_mmc(chip); if (retval != STATUS_SUCCESS) { - if (sd_check_err_code(chip, SD_NO_CARD)) - TRACE_RET(chip, STATUS_FAIL); + if (sd_check_err_code(chip, SD_NO_CARD)) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = reset_sd(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } } else { retval = reset_sd(chip); if (retval != STATUS_SUCCESS) { - if (sd_check_err_code(chip, SD_NO_CARD)) - TRACE_RET(chip, STATUS_FAIL); + if (sd_check_err_code(chip, SD_NO_CARD)) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (chip->sd_io) { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } else { retval = reset_mmc(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } } } retval = sd_set_clock_divider(chip, SD_CLK_DIVIDE_0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_WRITE_REG(chip, REG_SD_BYTE_CNT_L, 0xFF, 0); RTSX_WRITE_REG(chip, REG_SD_BYTE_CNT_H, 0xFF, 2); @@ -2967,8 +3257,10 @@ int reset_sd_card(struct rtsx_chip *chip) chip->capacity[chip->card2lun[SD_CARD]] = sd_card->capacity; retval = sd_set_init_para(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } dev_dbg(rtsx_dev(chip), "sd_card->sd_type = 0x%x\n", sd_card->sd_type); @@ -2994,20 +3286,28 @@ static int reset_mmc_only(struct rtsx_chip *chip) chip->capacity[chip->card2lun[SD_CARD]] = sd_card->capacity = 0; retval = enable_card_clock(chip, SD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sd_init_power(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = reset_mmc(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sd_set_clock_divider(chip, SD_CLK_DIVIDE_0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_WRITE_REG(chip, REG_SD_BYTE_CNT_L, 0xFF, 0); RTSX_WRITE_REG(chip, REG_SD_BYTE_CNT_H, 0xFF, 2); @@ -3015,8 +3315,10 @@ static int reset_mmc_only(struct rtsx_chip *chip) chip->capacity[chip->card2lun[SD_CARD]] = sd_card->capacity; retval = sd_set_init_para(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } dev_dbg(rtsx_dev(chip), "In reset_mmc_only, sd_card->sd_type = 0x%x\n", sd_card->sd_type); @@ -3034,15 +3336,18 @@ static int wait_data_buf_ready(struct rtsx_chip *chip) for (i = 0; i < WAIT_DATA_READY_RTY_CNT; i++) { if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) { sd_set_err_code(chip, SD_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } sd_card->sd_data_buf_ready = 0; retval = sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr, SD_RSP_TYPE_R1, NULL, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (sd_card->sd_data_buf_ready) { return sd_send_cmd_get_rsp(chip, SEND_STATUS, @@ -3052,7 +3357,8 @@ static int wait_data_buf_ready(struct rtsx_chip *chip) sd_set_err_code(chip, SD_TO_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } void sd_stop_seq_mode(struct rtsx_chip *chip) @@ -3120,8 +3426,10 @@ static inline int sd_auto_tune_clock(struct rtsx_chip *chip) } retval = sd_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -3158,7 +3466,8 @@ int sd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, u32 start_sector, chip->card_fail |= SD_CARD; chip->capacity[chip->card2lun[SD_CARD]] = 0; chip->rw_need_retry = 1; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -3172,7 +3481,8 @@ int sd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, u32 start_sector, retval = sd_switch_clock(chip); if (retval != STATUS_SUCCESS) { sd_set_err_code(chip, SD_IO_ERR); - TRACE_GOTO(chip, RW_FAIL); + rtsx_trace(chip); + goto RW_FAIL; } if (sd_card->seq_mode && @@ -3193,7 +3503,8 @@ int sd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, u32 start_sector, if (retval != STATUS_SUCCESS) { chip->rw_need_retry = 1; sd_set_err_code(chip, SD_STS_ERR); - TRACE_GOTO(chip, RW_FAIL); + rtsx_trace(chip); + goto RW_FAIL; } sd_card->seq_mode = 0; @@ -3201,7 +3512,8 @@ int sd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, u32 start_sector, retval = rtsx_write_register(chip, RBCTL, RB_FLUSH, RB_FLUSH); if (retval != STATUS_SUCCESS) { sd_set_err_code(chip, SD_IO_ERR); - TRACE_GOTO(chip, RW_FAIL); + rtsx_trace(chip); + goto RW_FAIL; } if ((sd_card->pre_sec_cnt < 0x80) @@ -3292,21 +3604,24 @@ int sd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, u32 start_sector, chip->rw_need_retry = 1; sd_set_err_code(chip, SD_TO_ERR); - TRACE_GOTO(chip, RW_FAIL); + rtsx_trace(chip); + goto RW_FAIL; } retval = wait_data_buf_ready(chip); if (retval != STATUS_SUCCESS) { chip->rw_need_retry = 1; sd_set_err_code(chip, SD_TO_ERR); - TRACE_GOTO(chip, RW_FAIL); + rtsx_trace(chip); + goto RW_FAIL; } retval = sd_send_cmd_get_rsp(chip, WRITE_MULTIPLE_BLOCK, data_addr, SD_RSP_TYPE_R1, NULL, 0); if (retval != STATUS_SUCCESS) { chip->rw_need_retry = 1; - TRACE_GOTO(chip, RW_FAIL); + rtsx_trace(chip); + goto RW_FAIL; } rtsx_init_cmd(chip); @@ -3350,7 +3665,8 @@ int sd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, u32 start_sector, if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) { chip->rw_need_retry = 0; dev_dbg(rtsx_dev(chip), "No card exist, exit sd_rw\n"); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } chip->rw_need_retry = 1; @@ -3359,21 +3675,25 @@ int sd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, u32 start_sector, SD_RSP_TYPE_R1b, NULL, 0); if (retval != STATUS_SUCCESS) { sd_set_err_code(chip, SD_STS_ERR); - TRACE_GOTO(chip, RW_FAIL); + rtsx_trace(chip); + goto RW_FAIL; } if (stat & (SD_CRC7_ERR | SD_CRC16_ERR | SD_CRC_WRITE_ERR)) { dev_dbg(rtsx_dev(chip), "SD CRC error, tune clock!\n"); sd_set_err_code(chip, SD_CRC_ERR); - TRACE_GOTO(chip, RW_FAIL); + rtsx_trace(chip); + goto RW_FAIL; } if (err == STATUS_TIMEDOUT) { sd_set_err_code(chip, SD_TO_ERR); - TRACE_GOTO(chip, RW_FAIL); + rtsx_trace(chip); + goto RW_FAIL; } - TRACE_RET(chip, err); + rtsx_trace(chip); + return err; } sd_card->pre_sec_addr = start_sector; @@ -3388,7 +3708,8 @@ RW_FAIL: if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) { chip->rw_need_retry = 0; dev_dbg(rtsx_dev(chip), "No card exist, exit sd_rw\n"); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (sd_check_err_code(chip, SD_CRC_ERR)) { @@ -3409,7 +3730,8 @@ RW_FAIL: } } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #ifdef SUPPORT_CPRM @@ -3475,13 +3797,16 @@ RTY_SEND_CMD: if (rsp_type & SD_WAIT_BUSY_END) { retval = sd_check_data0_status(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, retval); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return retval; + } } else { sd_set_err_code(chip, SD_TO_ERR); } } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (rsp_type == SD_RSP_TYPE_R0) @@ -3491,14 +3816,16 @@ RTY_SEND_CMD: if ((ptr[0] & 0xC0) != 0) { sd_set_err_code(chip, SD_STS_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (!(rsp_type & SD_NO_CHECK_CRC7)) { if (ptr[stat_idx] & SD_CRC7_ERR) { if (cmd_idx == WRITE_MULTIPLE_BLOCK) { sd_set_err_code(chip, SD_CRC_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (rty_cnt < SD_MAX_RETRY_COUNT) { wait_timeout(20); @@ -3506,7 +3833,8 @@ RTY_SEND_CMD: goto RTY_SEND_CMD; } else { sd_set_err_code(chip, SD_CRC_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } } @@ -3514,8 +3842,10 @@ RTY_SEND_CMD: if ((cmd_idx == SELECT_CARD) || (cmd_idx == APP_CMD) || (cmd_idx == SEND_STATUS) || (cmd_idx == STOP_TRANSMISSION)) { if ((cmd_idx != STOP_TRANSMISSION) && !special_check) { - if (ptr[1] & 0x80) - TRACE_RET(chip, STATUS_FAIL); + if (ptr[1] & 0x80) { + rtsx_trace(chip); + return STATUS_FAIL; + } } #ifdef SUPPORT_SD_LOCK if (ptr[1] & 0x7D) @@ -3523,19 +3853,26 @@ RTY_SEND_CMD: if (ptr[1] & 0x7F) #endif { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; + } + if (ptr[2] & 0xF8) { + rtsx_trace(chip); + return STATUS_FAIL; } - if (ptr[2] & 0xF8) - TRACE_RET(chip, STATUS_FAIL); if (cmd_idx == SELECT_CARD) { if (rsp_type == SD_RSP_TYPE_R2) { - if ((ptr[3] & 0x1E) != 0x04) - TRACE_RET(chip, STATUS_FAIL); + if ((ptr[3] & 0x1E) != 0x04) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else if (rsp_type == SD_RSP_TYPE_R0) { - if ((ptr[3] & 0x1E) != 0x03) - TRACE_RET(chip, STATUS_FAIL); + if ((ptr[3] & 0x1E) != 0x03) { + rtsx_trace(chip); + return STATUS_FAIL; + } } } } @@ -3572,8 +3909,10 @@ int ext_sd_get_rsp(struct rtsx_chip *chip, int len, u8 *rsp, u8 rsp_type) rtsx_add_cmd(chip, READ_REG_CMD, REG_SD_CMD5, 0xFF, 0); retval = rtsx_send_cmd(chip, SD_CARD, 100); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (rsp) { int min_len = (rsp_len < len) ? rsp_len : len; @@ -3619,7 +3958,8 @@ int sd_pass_thru_mode(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!(CHK_BIT(chip->lun_mc, lun))) { SET_BIT(chip->lun_mc, lun); set_sense_type(chip, lun, SENSE_TYPE_MEDIA_CHANGE); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if ((0x53 != srb->cmnd[2]) || (0x44 != srb->cmnd[3]) || @@ -3627,7 +3967,8 @@ int sd_pass_thru_mode(struct scsi_cmnd *srb, struct rtsx_chip *chip) (0x61 != srb->cmnd[6]) || (0x72 != srb->cmnd[7]) || (0x64 != srb->cmnd[8])) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } switch (srb->cmnd[1] & 0x0F) { @@ -3641,7 +3982,8 @@ int sd_pass_thru_mode(struct scsi_cmnd *srb, struct rtsx_chip *chip) default: set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } buf[5] = (1 == CHK_SD(sd_card)) ? 0x01 : 0x02; @@ -3709,17 +4051,21 @@ int sd_execute_no_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!sd_card->sd_pass_thru_en) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } retval = sd_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } if (sd_card->pre_cmd_err) { sd_card->pre_cmd_err = 0; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_CHANGE); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } cmd_idx = srb->cmnd[2] & 0x3F; @@ -3735,64 +4081,83 @@ int sd_execute_no_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = get_rsp_type(srb, &rsp_type, &rsp_len); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } sd_card->last_rsp_type = rsp_type; retval = sd_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } #ifdef SUPPORT_SD_LOCK if ((sd_card->sd_lock_status & SD_LOCK_1BIT_MODE) == 0) { if (CHK_MMC_8BIT(sd_card)) { retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03, SD_BUS_WIDTH_8); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } } else if (CHK_SD(sd_card) || CHK_MMC_4BIT(sd_card)) { retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03, SD_BUS_WIDTH_4); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } } } #else retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03, SD_BUS_WIDTH_4); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } #endif if (standby) { retval = sd_select_card(chip, 0); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Cmd_Failed; + } } if (acmd) { retval = ext_sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr, SD_RSP_TYPE_R1, NULL, 0, false); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Cmd_Failed; + } } retval = ext_sd_send_cmd_get_rsp(chip, cmd_idx, arg, rsp_type, sd_card->rsp, rsp_len, false); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Cmd_Failed; + } if (standby) { retval = sd_select_card(chip, 1); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Cmd_Failed; + } } #ifdef SUPPORT_SD_LOCK retval = sd_update_lock_status(chip); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Cmd_Failed; + } #endif scsi_set_resid(srb, 0); @@ -3806,7 +4171,8 @@ SD_Execute_Cmd_Failed: if (!(chip->card_ready & SD_CARD)) set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) @@ -3821,18 +4187,22 @@ int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!sd_card->sd_pass_thru_en) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (sd_card->pre_cmd_err) { sd_card->pre_cmd_err = 0; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_CHANGE); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } retval = sd_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } cmd_idx = srb->cmnd[2] & 0x3F; if (srb->cmnd[1] & 0x04) @@ -3850,13 +4220,16 @@ int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = get_rsp_type(srb, &rsp_type, &rsp_len); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } sd_card->last_rsp_type = rsp_type; retval = sd_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } #ifdef SUPPORT_SD_LOCK if ((sd_card->sd_lock_status & SD_LOCK_1BIT_MODE) == 0) { @@ -3877,22 +4250,28 @@ int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (data_len < 512) { retval = ext_sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, data_len, SD_RSP_TYPE_R1, NULL, 0, false); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Read_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Read_Cmd_Failed; + } } if (standby) { retval = sd_select_card(chip, 0); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Read_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Read_Cmd_Failed; + } } if (acmd) { retval = ext_sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr, SD_RSP_TYPE_R1, NULL, 0, false); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Read_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Read_Cmd_Failed; + } } if (data_len <= 512) { @@ -3911,8 +4290,10 @@ int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) cmd[4] = srb->cmnd[6]; buf = kmalloc(data_len, GFP_KERNEL); - if (buf == NULL) - TRACE_RET(chip, TRANSPORT_ERROR); + if (buf == NULL) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } retval = sd_read_data(chip, SD_TM_NORMAL_READ, cmd, 5, byte_cnt, blk_cnt, bus_width, buf, data_len, 2000); @@ -3920,7 +4301,8 @@ int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) read_err = true; kfree(buf); rtsx_clear_sd_error(chip); - TRACE_GOTO(chip, SD_Execute_Read_Cmd_Failed); + rtsx_trace(chip); + goto SD_Execute_Read_Cmd_Failed; } min_len = min(data_len, scsi_bufflen(srb)); @@ -3968,43 +4350,57 @@ int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (retval < 0) { read_err = true; rtsx_clear_sd_error(chip); - TRACE_GOTO(chip, SD_Execute_Read_Cmd_Failed); + rtsx_trace(chip); + goto SD_Execute_Read_Cmd_Failed; } } else { - TRACE_GOTO(chip, SD_Execute_Read_Cmd_Failed); + rtsx_trace(chip); + goto SD_Execute_Read_Cmd_Failed; } retval = ext_sd_get_rsp(chip, rsp_len, sd_card->rsp, rsp_type); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Read_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Read_Cmd_Failed; + } if (standby) { retval = sd_select_card(chip, 1); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Read_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Read_Cmd_Failed; + } } if (send_cmd12) { retval = ext_sd_send_cmd_get_rsp(chip, STOP_TRANSMISSION, 0, SD_RSP_TYPE_R1b, NULL, 0, false); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Read_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Read_Cmd_Failed; + } } if (data_len < 512) { retval = ext_sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, 0x200, SD_RSP_TYPE_R1, NULL, 0, false); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Read_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Read_Cmd_Failed; + } retval = rtsx_write_register(chip, SD_BYTE_CNT_H, 0xFF, 0x02); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Read_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Read_Cmd_Failed; + } retval = rtsx_write_register(chip, SD_BYTE_CNT_L, 0xFF, 0x00); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Read_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Read_Cmd_Failed; + } } if ((srb->cmnd[1] & 0x02) || (srb->cmnd[1] & 0x04)) @@ -4018,8 +4414,10 @@ int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (retval == STATUS_SUCCESS) break; } - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Read_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Read_Cmd_Failed; + } scsi_set_resid(srb, 0); return TRANSPORT_GOOD; @@ -4035,7 +4433,8 @@ SD_Execute_Read_Cmd_Failed: if (!(chip->card_ready & SD_CARD)) set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) @@ -4055,18 +4454,22 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!sd_card->sd_pass_thru_en) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (sd_card->pre_cmd_err) { sd_card->pre_cmd_err = 0; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_CHANGE); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } retval = sd_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } cmd_idx = srb->cmnd[2] & 0x3F; if (srb->cmnd[1] & 0x04) @@ -4093,68 +4496,87 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = get_rsp_type(srb, &rsp_type, &rsp_len); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } sd_card->last_rsp_type = rsp_type; retval = sd_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } #ifdef SUPPORT_SD_LOCK if ((sd_card->sd_lock_status & SD_LOCK_1BIT_MODE) == 0) { if (CHK_MMC_8BIT(sd_card)) { retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03, SD_BUS_WIDTH_8); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } } else if (CHK_SD(sd_card) || CHK_MMC_4BIT(sd_card)) { retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03, SD_BUS_WIDTH_4); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } } } #else retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03, SD_BUS_WIDTH_4); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } #endif if (data_len < 512) { retval = ext_sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, data_len, SD_RSP_TYPE_R1, NULL, 0, false); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Write_Cmd_Failed; + } } if (standby) { retval = sd_select_card(chip, 0); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Write_Cmd_Failed; + } } if (acmd) { retval = ext_sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr, SD_RSP_TYPE_R1, NULL, 0, false); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Write_Cmd_Failed; + } } retval = ext_sd_send_cmd_get_rsp(chip, cmd_idx, arg, rsp_type, sd_card->rsp, rsp_len, false); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Write_Cmd_Failed; + } if (data_len <= 512) { u16 i; u8 *buf; buf = kmalloc(data_len, GFP_KERNEL); - if (buf == NULL) - TRACE_RET(chip, TRANSPORT_ERROR); + if (buf == NULL) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } rtsx_stor_get_xfer_buf(buf, data_len, srb); @@ -4172,7 +4594,8 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = rtsx_send_cmd(chip, 0, 250); if (retval != STATUS_SUCCESS) { kfree(buf); - TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); + rtsx_trace(chip); + goto SD_Execute_Write_Cmd_Failed; } rtsx_init_cmd(chip); @@ -4183,7 +4606,8 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = rtsx_send_cmd(chip, 0, 250); if (retval != STATUS_SUCCESS) { kfree(buf); - TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); + rtsx_trace(chip); + goto SD_Execute_Write_Cmd_Failed; } } else { rtsx_init_cmd(chip); @@ -4194,7 +4618,8 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = rtsx_send_cmd(chip, 0, 250); if (retval != STATUS_SUCCESS) { kfree(buf); - TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); + rtsx_trace(chip); + goto SD_Execute_Write_Cmd_Failed; } } @@ -4245,13 +4670,15 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) DMA_TO_DEVICE, 10000); } else { - TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); + rtsx_trace(chip); + goto SD_Execute_Write_Cmd_Failed; } if (retval < 0) { write_err = true; rtsx_clear_sd_error(chip); - TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); + rtsx_trace(chip); + goto SD_Execute_Write_Cmd_Failed; } #ifdef SUPPORT_SD_LOCK @@ -4277,30 +4704,40 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (standby) { retval = sd_select_card(chip, 1); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Write_Cmd_Failed; + } } if (send_cmd12) { retval = ext_sd_send_cmd_get_rsp(chip, STOP_TRANSMISSION, 0, SD_RSP_TYPE_R1b, NULL, 0, false); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Write_Cmd_Failed; + } } if (data_len < 512) { retval = ext_sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, 0x200, SD_RSP_TYPE_R1, NULL, 0, false); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Write_Cmd_Failed; + } retval = rtsx_write_register(chip, SD_BYTE_CNT_H, 0xFF, 0x02); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Write_Cmd_Failed; + } rtsx_write_register(chip, SD_BYTE_CNT_L, 0xFF, 0x00); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Write_Cmd_Failed; + } } if ((srb->cmnd[1] & 0x02) || (srb->cmnd[1] & 0x04)) @@ -4314,8 +4751,10 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (retval == STATUS_SUCCESS) break; } - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto SD_Execute_Write_Cmd_Failed; + } #ifdef SUPPORT_SD_LOCK if (cmd_idx == LOCK_UNLOCK) { @@ -4341,7 +4780,8 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = reset_sd(chip); if (retval != STATUS_SUCCESS) { sd_card->sd_lock_status &= ~(SD_UNLOCK_POW_ON | SD_SDR_RST); - TRACE_GOTO(chip, SD_Execute_Write_Cmd_Failed); + rtsx_trace(chip); + goto SD_Execute_Write_Cmd_Failed; } } @@ -4354,7 +4794,8 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (lock_cmd_fail) { scsi_set_resid(srb, 0); set_sense_type(chip, lun, SENSE_TYPE_NO_SENSE); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } #endif /* SUPPORT_SD_LOCK */ @@ -4372,7 +4813,8 @@ SD_Execute_Write_Cmd_Failed: if (!(chip->card_ready & SD_CARD)) set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } int sd_get_cmd_rsp(struct scsi_cmnd *srb, struct rtsx_chip *chip) @@ -4384,20 +4826,23 @@ int sd_get_cmd_rsp(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!sd_card->sd_pass_thru_en) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (sd_card->pre_cmd_err) { sd_card->pre_cmd_err = 0; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_CHANGE); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } data_len = ((u16)srb->cmnd[7] << 8) | srb->cmnd[8]; if (sd_card->last_rsp_type == SD_RSP_TYPE_R0) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } else if (sd_card->last_rsp_type == SD_RSP_TYPE_R2) { count = (data_len < 17) ? data_len : 17; } else { @@ -4422,13 +4867,15 @@ int sd_hw_rst(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!sd_card->sd_pass_thru_en) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (sd_card->pre_cmd_err) { sd_card->pre_cmd_err = 0; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_CHANGE); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if ((0x53 != srb->cmnd[2]) || (0x44 != srb->cmnd[3]) || @@ -4436,7 +4883,8 @@ int sd_hw_rst(struct scsi_cmnd *srb, struct rtsx_chip *chip) (0x61 != srb->cmnd[6]) || (0x72 != srb->cmnd[7]) || (0x64 != srb->cmnd[8])) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } switch (srb->cmnd[1] & 0x0F) { @@ -4452,7 +4900,8 @@ int sd_hw_rst(struct scsi_cmnd *srb, struct rtsx_chip *chip) #endif set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); sd_card->pre_cmd_err = 1; - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } #ifdef SUPPORT_SD_LOCK sd_card->sd_lock_status &= ~SD_SDR_RST; @@ -4464,13 +4913,15 @@ int sd_hw_rst(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); sd_card->pre_cmd_err = 1; - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } break; default: set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } scsi_set_resid(srb, 0); @@ -4494,23 +4945,29 @@ int sd_power_off_card3v3(struct rtsx_chip *chip) int retval; retval = disable_card_clock(chip, SD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_WRITE_REG(chip, CARD_OE, SD_OUTPUT_EN, 0); if (!chip->ft2_fast_mode) { retval = card_power_off(chip, SD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } wait_timeout(50); } if (chip->asic_code) { retval = sd_pull_ctl_disable(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else { RTSX_WRITE_REG(chip, FPGA_PULL_CTL, FPGA_SD_PULL_CTL_BIT | 0x20, FPGA_SD_PULL_CTL_BIT); @@ -4540,8 +4997,10 @@ int release_sd_card(struct rtsx_chip *chip) memset(sd_card->raw_scr, 0, 8); retval = sd_power_off_card3v3(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } |