From: Joe Perches Date: Wed, 25 Mar 2015 19:54:25 +0000 (-0700) Subject: staging: rts5208: Remove TRACE_RET and TRACE_GOTO macros X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=031366ea65495f787eb792a135f51c093d75a197;p=linux-beck.git 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/rts5208/Makefile b/drivers/staging/rts5208/Makefile index 17b4471c4d6d..f7fd03a94e5f 100644 --- a/drivers/staging/rts5208/Makefile +++ b/drivers/staging/rts5208/Makefile @@ -3,4 +3,4 @@ obj-$(CONFIG_RTS5208) := rts5208.o ccflags-y := -Idrivers/scsi rts5208-y := rtsx.o rtsx_chip.o rtsx_transport.o rtsx_scsi.o \ - rtsx_card.o general.o sd.o xd.o ms.o spi.o + rtsx_card.o general.o sd.o xd.o ms.o spi.o trace.o diff --git a/drivers/staging/rts5208/ms.c b/drivers/staging/rts5208/ms.c index 4c38ff9d9a76..dcaec195cdcc 100644 --- a/drivers/staging/rts5208/ms.c +++ b/drivers/staging/rts5208/ms.c @@ -26,9 +26,6 @@ #include #include "rtsx.h" -#include "rtsx_transport.h" -#include "rtsx_scsi.h" -#include "rtsx_card.h" #include "ms.h" static inline void ms_set_err_code(struct rtsx_chip *chip, u8 err_code) @@ -47,7 +44,8 @@ static inline int ms_check_err_code(struct rtsx_chip *chip, u8 err_code) static int ms_parse_err_code(struct rtsx_chip *chip) { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } static int ms_transfer_tpc(struct rtsx_chip *chip, u8 trans_mode, @@ -78,7 +76,8 @@ static int ms_transfer_tpc(struct rtsx_chip *chip, u8 trans_mode, if (retval < 0) { rtsx_clear_ms_error(chip); ms_set_err_code(chip, MS_TO_ERROR); - TRACE_RET(chip, ms_parse_err_code(chip)); + rtsx_trace(chip); + return ms_parse_err_code(chip); } ptr = rtsx_get_cmd_data(chip) + 1; @@ -86,13 +85,15 @@ static int ms_transfer_tpc(struct rtsx_chip *chip, u8 trans_mode, if (!(tpc & 0x08)) { /* Read Packet */ if (*ptr & MS_CRC16_ERR) { ms_set_err_code(chip, MS_CRC16_ERROR); - TRACE_RET(chip, ms_parse_err_code(chip)); + rtsx_trace(chip); + return ms_parse_err_code(chip); } } else { /* Write Packet */ if (CHK_MSPRO(ms_card) && !(*ptr & 0x80)) { if (*ptr & (MS_INT_ERR | MS_INT_CMDNK)) { ms_set_err_code(chip, MS_CMD_NK); - TRACE_RET(chip, ms_parse_err_code(chip)); + rtsx_trace(chip); + return ms_parse_err_code(chip); } } } @@ -100,7 +101,8 @@ static int ms_transfer_tpc(struct rtsx_chip *chip, u8 trans_mode, if (*ptr & MS_RDY_TIMEOUT) { rtsx_clear_ms_error(chip); ms_set_err_code(chip, MS_TO_ERROR); - TRACE_RET(chip, ms_parse_err_code(chip)); + rtsx_trace(chip); + return ms_parse_err_code(chip); } return STATUS_SUCCESS; @@ -114,8 +116,10 @@ static int ms_transfer_data(struct rtsx_chip *chip, u8 trans_mode, u8 val, err_code = 0; enum dma_data_direction dir; - if (!buf || !buf_len) - TRACE_RET(chip, STATUS_FAIL); + if (!buf || !buf_len) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (trans_mode == MS_TM_AUTO_READ) { dir = DMA_FROM_DEVICE; @@ -124,7 +128,8 @@ static int ms_transfer_data(struct rtsx_chip *chip, u8 trans_mode, dir = DMA_TO_DEVICE; err_code = MS_FLASH_WRITE_ERROR; } else { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } rtsx_init_cmd(chip); @@ -160,12 +165,15 @@ static int ms_transfer_data(struct rtsx_chip *chip, u8 trans_mode, else retval = STATUS_FAIL; - TRACE_RET(chip, retval); + rtsx_trace(chip); + return retval; } RTSX_READ_REG(chip, MS_TRANS_CFG, &val); - if (val & (MS_INT_CMDNK | MS_INT_ERR | MS_CRC16_ERR | MS_RDY_TIMEOUT)) - TRACE_RET(chip, STATUS_FAIL); + if (val & (MS_INT_CMDNK | MS_INT_ERR | MS_CRC16_ERR | MS_RDY_TIMEOUT)) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -176,8 +184,10 @@ static int ms_write_bytes(struct rtsx_chip *chip, struct ms_info *ms_card = &(chip->ms_card); int retval, i; - if (!data || (data_len < cnt)) - TRACE_RET(chip, STATUS_ERROR); + if (!data || (data_len < cnt)) { + rtsx_trace(chip); + return STATUS_ERROR; + } rtsx_init_cmd(chip); @@ -211,25 +221,28 @@ static int ms_write_bytes(struct rtsx_chip *chip, if (!(tpc & 0x08)) { if (val & MS_CRC16_ERR) { ms_set_err_code(chip, MS_CRC16_ERROR); - TRACE_RET(chip, ms_parse_err_code(chip)); + rtsx_trace(chip); + return ms_parse_err_code(chip); } } else { if (CHK_MSPRO(ms_card) && !(val & 0x80)) { if (val & (MS_INT_ERR | MS_INT_CMDNK)) { ms_set_err_code(chip, MS_CMD_NK); - TRACE_RET(chip, - ms_parse_err_code(chip)); + rtsx_trace(chip); + return ms_parse_err_code(chip); } } } if (val & MS_RDY_TIMEOUT) { ms_set_err_code(chip, MS_TO_ERROR); - TRACE_RET(chip, ms_parse_err_code(chip)); + rtsx_trace(chip); + return ms_parse_err_code(chip); } ms_set_err_code(chip, MS_TO_ERROR); - TRACE_RET(chip, ms_parse_err_code(chip)); + rtsx_trace(chip); + return ms_parse_err_code(chip); } return STATUS_SUCCESS; @@ -242,8 +255,10 @@ static int ms_read_bytes(struct rtsx_chip *chip, int retval, i; u8 *ptr; - if (!data) - TRACE_RET(chip, STATUS_ERROR); + if (!data) { + rtsx_trace(chip); + return STATUS_ERROR; + } rtsx_init_cmd(chip); @@ -277,25 +292,28 @@ static int ms_read_bytes(struct rtsx_chip *chip, if (!(tpc & 0x08)) { if (val & MS_CRC16_ERR) { ms_set_err_code(chip, MS_CRC16_ERROR); - TRACE_RET(chip, ms_parse_err_code(chip)); + rtsx_trace(chip); + return ms_parse_err_code(chip); } } else { if (CHK_MSPRO(ms_card) && !(val & 0x80)) { if (val & (MS_INT_ERR | MS_INT_CMDNK)) { ms_set_err_code(chip, MS_CMD_NK); - TRACE_RET(chip, - ms_parse_err_code(chip)); + rtsx_trace(chip); + return ms_parse_err_code(chip); } } } if (val & MS_RDY_TIMEOUT) { ms_set_err_code(chip, MS_TO_ERROR); - TRACE_RET(chip, ms_parse_err_code(chip)); + rtsx_trace(chip); + return ms_parse_err_code(chip); } ms_set_err_code(chip, MS_TO_ERROR); - TRACE_RET(chip, ms_parse_err_code(chip)); + rtsx_trace(chip); + return ms_parse_err_code(chip); } ptr = rtsx_get_cmd_data(chip) + 1; @@ -331,7 +349,8 @@ static int ms_set_rw_reg_addr(struct rtsx_chip *chip, rtsx_clear_ms_error(chip); } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } static int ms_send_cmd(struct rtsx_chip *chip, u8 cmd, u8 cfg) @@ -369,12 +388,16 @@ static int ms_set_init_para(struct rtsx_chip *chip) } retval = switch_clock(chip, ms_card->ms_clock); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = select_card(chip, MS_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -385,12 +408,16 @@ static int ms_switch_clock(struct rtsx_chip *chip) int retval; retval = select_card(chip, MS_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = switch_clock(chip, ms_card->ms_clock); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -455,8 +482,10 @@ static int ms_pull_ctl_enable(struct rtsx_chip *chip) } retval = rtsx_send_cmd(chip, MS_CARD, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -475,20 +504,26 @@ static int ms_prepare_reset(struct rtsx_chip *chip) ms_card->pro_under_formatting = 0; retval = ms_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, MS_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 = ms_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_MS_PULL_CTL_BIT | 0x20, 0); @@ -496,8 +531,10 @@ static int ms_prepare_reset(struct rtsx_chip *chip) if (!chip->ft2_fast_mode) { retval = card_power_on(chip, MS_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } wait_timeout(150); @@ -510,7 +547,8 @@ static int ms_prepare_reset(struct rtsx_chip *chip) if (chip->ocp_stat & oc_mask) { 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 } @@ -532,8 +570,10 @@ static int ms_prepare_reset(struct rtsx_chip *chip) MS_STOP | MS_CLR_ERR, MS_STOP | MS_CLR_ERR); retval = ms_set_init_para(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -545,8 +585,10 @@ static int ms_identify_media_type(struct rtsx_chip *chip, int switch_8bit_bus) u8 val; retval = ms_set_rw_reg_addr(chip, Pro_StatusReg, 6, SystemParm, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } for (i = 0; i < MS_MAX_RETRY_COUNT; i++) { retval = ms_transfer_tpc(chip, MS_TM_READ_BYTES, READ_REG, @@ -554,8 +596,10 @@ static int ms_identify_media_type(struct rtsx_chip *chip, int switch_8bit_bus) if (retval == STATUS_SUCCESS) break; } - if (i == MS_MAX_RETRY_COUNT) - TRACE_RET(chip, STATUS_FAIL); + if (i == MS_MAX_RETRY_COUNT) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_READ_REG(chip, PPBUF_BASE2 + 2, &val); dev_dbg(rtsx_dev(chip), "Type register: 0x%x\n", val); @@ -563,14 +607,16 @@ static int ms_identify_media_type(struct rtsx_chip *chip, int switch_8bit_bus) if (val != 0x02) ms_card->check_ms_flow = 1; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } RTSX_READ_REG(chip, PPBUF_BASE2 + 4, &val); dev_dbg(rtsx_dev(chip), "Category register: 0x%x\n", val); if (val != 0) { ms_card->check_ms_flow = 1; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } RTSX_READ_REG(chip, PPBUF_BASE2 + 5, &val); @@ -586,7 +632,8 @@ static int ms_identify_media_type(struct rtsx_chip *chip, int switch_8bit_bus) chip->card_wp |= MS_CARD; } else { ms_card->check_ms_flow = 1; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } ms_card->ms_type |= TYPE_MSPRO; @@ -602,7 +649,8 @@ static int ms_identify_media_type(struct rtsx_chip *chip, int switch_8bit_bus) ms_card->ms_type &= 0x0F; } else { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -618,7 +666,8 @@ static int ms_confirm_cpu_startup(struct rtsx_chip *chip) do { if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) { ms_set_err_code(chip, MS_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } for (i = 0; i < MS_MAX_RETRY_COUNT; i++) { @@ -627,11 +676,15 @@ static int ms_confirm_cpu_startup(struct rtsx_chip *chip) if (retval == STATUS_SUCCESS) break; } - if (i == MS_MAX_RETRY_COUNT) - TRACE_RET(chip, STATUS_FAIL); + if (i == MS_MAX_RETRY_COUNT) { + rtsx_trace(chip); + return STATUS_FAIL; + } - if (k > 100) - TRACE_RET(chip, STATUS_FAIL); + if (k > 100) { + rtsx_trace(chip); + return STATUS_FAIL; + } k++; wait_timeout(100); @@ -642,14 +695,18 @@ static int ms_confirm_cpu_startup(struct rtsx_chip *chip) if (retval == STATUS_SUCCESS) break; } - if (i == MS_MAX_RETRY_COUNT) - TRACE_RET(chip, STATUS_FAIL); + if (i == MS_MAX_RETRY_COUNT) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (val & INT_REG_ERR) { if (val & INT_REG_CMDNK) chip->card_wp |= (MS_CARD); - else - TRACE_RET(chip, STATUS_FAIL); + else { + rtsx_trace(chip); + return STATUS_FAIL; + } } /* -- end confirm CPU startup */ @@ -669,8 +726,10 @@ static int ms_switch_parallel_bus(struct rtsx_chip *chip) if (retval == STATUS_SUCCESS) break; } - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -689,21 +748,27 @@ static int ms_switch_8bit_bus(struct rtsx_chip *chip) if (retval == STATUS_SUCCESS) break; } - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_WRITE_REG(chip, MS_CFG, 0x98, MS_BUS_WIDTH_8 | SAMPLE_TIME_FALLING); ms_card->ms_type |= MS_8BIT; retval = ms_set_init_para(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } for (i = 0; i < MS_MAX_RETRY_COUNT; i++) { retval = ms_transfer_tpc(chip, MS_TM_READ_BYTES, GET_INT, 1, NO_WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -716,22 +781,29 @@ static int ms_pro_reset_flow(struct rtsx_chip *chip, int switch_8bit_bus) for (i = 0; i < 3; i++) { retval = ms_prepare_reset(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_identify_media_type(chip, switch_8bit_bus); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_confirm_cpu_startup(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_switch_parallel_bus(chip); if (retval != STATUS_SUCCESS) { if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) { ms_set_err_code(chip, MS_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } continue; } else { @@ -739,23 +811,28 @@ static int ms_pro_reset_flow(struct rtsx_chip *chip, int switch_8bit_bus) } } - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } /* Switch MS-PRO into Parallel mode */ RTSX_WRITE_REG(chip, MS_CFG, 0x18, MS_BUS_WIDTH_4); RTSX_WRITE_REG(chip, MS_CFG, PUSH_TIME_ODD, PUSH_TIME_ODD); retval = ms_set_init_para(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } /* If MSPro HG Card, We shall try to switch to 8-bit bus */ if (CHK_MSHG(ms_card) && chip->support_ms_8bit && switch_8bit_bus) { retval = ms_switch_8bit_bus(chip); if (retval != STATUS_SUCCESS) { ms_card->switch_8bit_fail = 1; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -771,8 +848,10 @@ static int msxc_change_power(struct rtsx_chip *chip, u8 mode) ms_cleanup_work(chip); retval = ms_set_rw_reg_addr(chip, 0, 0, Pro_DataCount1, 6); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } buf[0] = 0; buf[1] = mode; @@ -782,16 +861,22 @@ static int msxc_change_power(struct rtsx_chip *chip, u8 mode) buf[5] = 0; retval = ms_write_bytes(chip, PRO_WRITE_REG, 6, NO_WAIT_INT, buf, 6); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_send_cmd(chip, XC_CHG_POWER, WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_READ_REG(chip, MS_TRANS_CFG, buf); - if (buf[0] & (MS_INT_CMDNK | MS_INT_ERR)) - TRACE_RET(chip, STATUS_FAIL); + if (buf[0] & (MS_INT_CMDNK | MS_INT_ERR)) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -813,8 +898,10 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) #endif retval = ms_set_rw_reg_addr(chip, Pro_IntReg, 2, Pro_SystemParm, 7); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (CHK_MS8BIT(ms_card)) data[0] = PARALLEL_8BIT_IF; @@ -836,12 +923,16 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) if (retval == STATUS_SUCCESS) break; } - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } buf = kmalloc(64 * 512, GFP_KERNEL); - if (buf == NULL) - TRACE_RET(chip, STATUS_ERROR); + if (buf == NULL) { + rtsx_trace(chip); + return STATUS_ERROR; + } for (i = 0; i < MS_MAX_RETRY_COUNT; i++) { retval = ms_send_cmd(chip, PRO_READ_ATRB, WAIT_INT); @@ -851,11 +942,13 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) retval = rtsx_read_register(chip, MS_TRANS_CFG, &val); if (retval != STATUS_SUCCESS) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (!(val & MS_INT_BREQ)) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = ms_transfer_data(chip, MS_TM_AUTO_READ, PRO_READ_LONG_DATA, 0x40, WAIT_INT, @@ -867,7 +960,8 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) } if (retval != STATUS_SUCCESS) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } i = 0; @@ -875,7 +969,8 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) retval = rtsx_read_register(chip, MS_TRANS_CFG, &val); if (retval != STATUS_SUCCESS) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if ((val & MS_INT_CED) || !(val & MS_INT_BREQ)) @@ -885,7 +980,8 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) PRO_READ_LONG_DATA, 0, WAIT_INT); if (retval != STATUS_SUCCESS) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } i++; @@ -893,18 +989,21 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) if (retval != STATUS_SUCCESS) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if ((buf[0] != 0xa5) && (buf[1] != 0xc3)) { /* Signature code is wrong */ kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if ((buf[4] < 1) || (buf[4] > 12)) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } for (i = 0; i < buf[4]; i++) { @@ -929,15 +1028,18 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) sys_info_addr, sys_info_size); if (sys_info_size != 96) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (sys_info_addr < 0x1A0) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if ((sys_info_size + sys_info_addr) > 0x8000) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #ifdef SUPPORT_MSXC @@ -964,15 +1066,18 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) model_name_addr, model_name_size); if (model_name_size != 48) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (model_name_addr < 0x1A0) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if ((model_name_size + model_name_addr) > 0x8000) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } found_model_name = 1; @@ -985,7 +1090,8 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) if (i == buf[4]) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } class_code = buf[sys_info_addr + 0]; @@ -1030,15 +1136,21 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) #ifdef SUPPORT_MSXC if (CHK_MSXC(ms_card)) { - if (class_code != 0x03) - TRACE_RET(chip, STATUS_FAIL); + if (class_code != 0x03) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else { - if (class_code != 0x02) - TRACE_RET(chip, STATUS_FAIL); + if (class_code != 0x02) { + rtsx_trace(chip); + return STATUS_FAIL; + } } #else - if (class_code != 0x02) - TRACE_RET(chip, STATUS_FAIL); + if (class_code != 0x02) { + rtsx_trace(chip); + return STATUS_FAIL; + } #endif if (device_type != 0x00) { @@ -1046,12 +1158,15 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) (device_type == 0x03)) { chip->card_wp |= MS_CARD; } else { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } - if (sub_class & 0xC0) - TRACE_RET(chip, STATUS_FAIL); + if (sub_class & 0xC0) { + rtsx_trace(chip); + return STATUS_FAIL; + } dev_dbg(rtsx_dev(chip), "class_code: 0x%x, device_type: 0x%x, sub_class: 0x%x\n", class_code, device_type, sub_class); @@ -1099,16 +1214,21 @@ Retry: if (retval != STATUS_SUCCESS) { if (ms_card->switch_8bit_fail) { retval = ms_pro_reset_flow(chip, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } retval = ms_read_attribute_info(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } #ifdef XC_POWERCLASS if (CHK_HG8BIT(ms_card)) @@ -1148,8 +1268,10 @@ Retry: #ifdef SUPPORT_MAGIC_GATE retval = mg_set_tpc_para_sub(chip, 0, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } #endif if (CHK_HG8BIT(ms_card)) @@ -1166,16 +1288,21 @@ static int ms_read_status_reg(struct rtsx_chip *chip) u8 val[2]; retval = ms_set_rw_reg_addr(chip, StatusReg0, 2, 0, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_read_bytes(chip, READ_REG, 2, NO_WAIT_INT, val, 2); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (val[1] & (STS_UCDT | STS_UCEX | STS_UCFG)) { ms_set_err_code(chip, MS_FLASH_READ_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -1191,8 +1318,10 @@ static int ms_read_extra_data(struct rtsx_chip *chip, retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, SystemParm, 6); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (CHK_MS4BIT(ms_card)) { /* Parallel interface */ @@ -1213,8 +1342,10 @@ static int ms_read_extra_data(struct rtsx_chip *chip, if (retval == STATUS_SUCCESS) break; } - if (i == MS_MAX_RETRY_COUNT) - TRACE_RET(chip, STATUS_FAIL); + if (i == MS_MAX_RETRY_COUNT) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_set_err_code(chip, MS_NO_ERROR); @@ -1223,35 +1354,46 @@ static int ms_read_extra_data(struct rtsx_chip *chip, if (retval == STATUS_SUCCESS) break; } - if (i == MS_MAX_RETRY_COUNT) - TRACE_RET(chip, STATUS_FAIL); + if (i == MS_MAX_RETRY_COUNT) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_set_err_code(chip, MS_NO_ERROR); retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (val & INT_REG_CMDNK) { ms_set_err_code(chip, MS_CMD_NK); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (val & INT_REG_CED) { if (val & INT_REG_ERR) { retval = ms_read_status_reg(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, SystemParm, 6); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } } retval = ms_read_bytes(chip, READ_REG, MS_EXTRA_SIZE, NO_WAIT_INT, data, MS_EXTRA_SIZE); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (buf && buf_len) { if (buf_len > MS_EXTRA_SIZE) @@ -1269,13 +1411,17 @@ static int ms_write_extra_data(struct rtsx_chip *chip, int retval, i; u8 val, data[16]; - if (!buf || (buf_len < MS_EXTRA_SIZE)) - TRACE_RET(chip, STATUS_FAIL); + if (!buf || (buf_len < MS_EXTRA_SIZE)) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, SystemParm, 6 + MS_EXTRA_SIZE); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (CHK_MS4BIT(ms_card)) data[0] = 0x88; @@ -1293,26 +1439,34 @@ static int ms_write_extra_data(struct rtsx_chip *chip, retval = ms_write_bytes(chip, WRITE_REG, (6 + MS_EXTRA_SIZE), NO_WAIT_INT, data, 16); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_set_err_code(chip, MS_NO_ERROR); retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (val & INT_REG_CMDNK) { ms_set_err_code(chip, MS_CMD_NK); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (val & INT_REG_CED) { if (val & INT_REG_ERR) { ms_set_err_code(chip, MS_FLASH_WRITE_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1328,8 +1482,10 @@ static int ms_read_page(struct rtsx_chip *chip, u16 block_addr, u8 page_num) retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, SystemParm, 6); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (CHK_MS4BIT(ms_card)) data[0] = 0x88; @@ -1343,28 +1499,36 @@ static int ms_read_page(struct rtsx_chip *chip, u16 block_addr, u8 page_num) data[5] = page_num; retval = ms_write_bytes(chip, WRITE_REG, 6, NO_WAIT_INT, data, 6); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_send_cmd(chip, BLOCK_READ, WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_set_err_code(chip, MS_NO_ERROR); retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (val & INT_REG_CMDNK) { ms_set_err_code(chip, MS_CMD_NK); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (val & INT_REG_CED) { if (val & INT_REG_ERR) { if (!(val & INT_REG_BREQ)) { ms_set_err_code(chip, MS_FLASH_READ_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = ms_read_status_reg(chip); if (retval != STATUS_SUCCESS) @@ -1373,18 +1537,23 @@ static int ms_read_page(struct rtsx_chip *chip, u16 block_addr, u8 page_num) } else { if (!(val & INT_REG_BREQ)) { ms_set_err_code(chip, MS_BREQ_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } } retval = ms_transfer_tpc(chip, MS_TM_NORMAL_READ, READ_PAGE_DATA, 0, NO_WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } - if (ms_check_err_code(chip, MS_FLASH_WRITE_ERROR)) - TRACE_RET(chip, STATUS_FAIL); + if (ms_check_err_code(chip, MS_FLASH_WRITE_ERROR)) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -1397,13 +1566,17 @@ static int ms_set_bad_block(struct rtsx_chip *chip, u16 phy_blk) u8 val, data[8], extra[MS_EXTRA_SIZE]; retval = ms_read_extra_data(chip, phy_blk, 0, extra, MS_EXTRA_SIZE); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, SystemParm, 7); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_set_err_code(chip, MS_NO_ERROR); @@ -1421,27 +1594,35 @@ static int ms_set_bad_block(struct rtsx_chip *chip, u16 phy_blk) data[7] = 0xFF; retval = ms_write_bytes(chip, WRITE_REG, 7, NO_WAIT_INT, data, 7); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_set_err_code(chip, MS_NO_ERROR); retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (val & INT_REG_CMDNK) { ms_set_err_code(chip, MS_CMD_NK); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (val & INT_REG_CED) { if (val & INT_REG_ERR) { ms_set_err_code(chip, MS_FLASH_WRITE_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1457,8 +1638,10 @@ static int ms_erase_block(struct rtsx_chip *chip, u16 phy_blk) retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, SystemParm, 6); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_set_err_code(chip, MS_NO_ERROR); @@ -1474,18 +1657,24 @@ static int ms_erase_block(struct rtsx_chip *chip, u16 phy_blk) data[5] = 0; retval = ms_write_bytes(chip, WRITE_REG, 6, NO_WAIT_INT, data, 6); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ERASE_RTY: retval = ms_send_cmd(chip, BLOCK_ERASE, WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_set_err_code(chip, MS_NO_ERROR); retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (val & INT_REG_CMDNK) { if (i < 3) { @@ -1495,13 +1684,15 @@ ERASE_RTY: ms_set_err_code(chip, MS_CMD_NK); ms_set_bad_block(chip, phy_blk); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (val & INT_REG_CED) { if (val & INT_REG_ERR) { ms_set_err_code(chip, MS_FLASH_WRITE_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1544,13 +1735,16 @@ static int ms_init_page(struct rtsx_chip *chip, u16 phy_blk, u16 log_blk, for (i = start_page; i < end_page; i++) { if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) { ms_set_err_code(chip, MS_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = ms_write_extra_data(chip, phy_blk, i, extra, MS_EXTRA_SIZE); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -1570,42 +1764,54 @@ static int ms_copy_page(struct rtsx_chip *chip, u16 old_blk, u16 new_blk, start_page, end_page); retval = ms_read_extra_data(chip, new_blk, 0, extra, MS_EXTRA_SIZE); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_read_status_reg(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_READ_REG(chip, PPBUF_BASE2, &val); if (val & BUF_FULL) { retval = ms_send_cmd(chip, CLEAR_BUF, WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (!(val & INT_REG_CED)) { ms_set_err_code(chip, MS_FLASH_WRITE_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } for (i = start_page; i < end_page; i++) { if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) { ms_set_err_code(chip, MS_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } ms_read_extra_data(chip, old_blk, i, extra, MS_EXTRA_SIZE); retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, SystemParm, 6); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_set_err_code(chip, MS_NO_ERROR); @@ -1622,21 +1828,28 @@ static int ms_copy_page(struct rtsx_chip *chip, u16 old_blk, u16 new_blk, retval = ms_write_bytes(chip, WRITE_REG, 6, NO_WAIT_INT, data, 6); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_send_cmd(chip, BLOCK_READ, WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_set_err_code(chip, MS_NO_ERROR); retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (val & INT_REG_CMDNK) { ms_set_err_code(chip, MS_CMD_NK); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (val & INT_REG_CED) { @@ -1653,8 +1866,10 @@ static int ms_copy_page(struct rtsx_chip *chip, u16 old_blk, u16 new_blk, MS_TM_NORMAL_READ, READ_PAGE_DATA, 0, NO_WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (uncorrect_flag) { ms_set_page_status(log_blk, setPS_NG, @@ -1685,13 +1900,16 @@ static int ms_copy_page(struct rtsx_chip *chip, u16 old_blk, u16 new_blk, if (retval == STATUS_SUCCESS) break; } - if (rty_cnt == MS_MAX_RETRY_COUNT) - TRACE_RET(chip, STATUS_FAIL); + if (rty_cnt == MS_MAX_RETRY_COUNT) { + rtsx_trace(chip); + return STATUS_FAIL; + } } if (!(val & INT_REG_BREQ)) { ms_set_err_code(chip, MS_BREQ_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1725,35 +1943,45 @@ static int ms_copy_page(struct rtsx_chip *chip, u16 old_blk, u16 new_blk, retval = ms_write_bytes(chip, WRITE_REG, (6 + MS_EXTRA_SIZE), NO_WAIT_INT, data, 16); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_set_err_code(chip, MS_NO_ERROR); retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (val & INT_REG_CMDNK) { ms_set_err_code(chip, MS_CMD_NK); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (val & INT_REG_CED) { if (val & INT_REG_ERR) { ms_set_err_code(chip, MS_FLASH_WRITE_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } if (i == 0) { retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, SystemParm, 7); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_set_err_code(chip, MS_NO_ERROR); @@ -1772,29 +2000,37 @@ static int ms_copy_page(struct rtsx_chip *chip, u16 old_blk, u16 new_blk, retval = ms_write_bytes(chip, WRITE_REG, 7, NO_WAIT_INT, data, 8); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_set_err_code(chip, MS_NO_ERROR); retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (val & INT_REG_CMDNK) { ms_set_err_code(chip, MS_CMD_NK); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (val & INT_REG_CED) { if (val & INT_REG_ERR) { ms_set_err_code(chip, MS_FLASH_WRITE_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } } @@ -1815,18 +2051,24 @@ static int reset_ms(struct rtsx_chip *chip) #endif retval = ms_prepare_reset(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_card->ms_type |= TYPE_MS; retval = ms_send_cmd(chip, MS_RESET, NO_WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_read_status_reg(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_READ_REG(chip, PPBUF_BASE2, &val); if (val & WRT_PRTCT) @@ -1841,7 +2083,8 @@ RE_SEARCH: while (i < (MAX_DEFECTIVE_BLOCK + 2)) { if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) { ms_set_err_code(chip, MS_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = ms_read_extra_data(chip, i, 0, extra, MS_EXTRA_SIZE); @@ -1861,7 +2104,8 @@ RE_SEARCH: if (i == (MAX_DEFECTIVE_BLOCK + 2)) { dev_dbg(rtsx_dev(chip), "No boot block found!"); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } for (j = 0; j < 3; j++) { @@ -1876,8 +2120,10 @@ RE_SEARCH: } retval = ms_read_page(chip, ms_card->boot_block, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } /* Read MS system information as sys_info */ rtsx_init_cmd(chip); @@ -1886,8 +2132,10 @@ RE_SEARCH: rtsx_add_cmd(chip, READ_REG_CMD, PPBUF_BASE2 + 0x1A0 + i, 0, 0); retval = rtsx_send_cmd(chip, MS_CARD, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } ptr = rtsx_get_cmd_data(chip); memcpy(ms_card->raw_sys_info, ptr, 96); @@ -1909,8 +2157,10 @@ RE_SEARCH: rtsx_add_cmd(chip, READ_REG_CMD, MS_4bit_Support, 0, 0); retval = rtsx_send_cmd(chip, MS_CARD, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } ptr = rtsx_get_cmd_data(chip); @@ -1983,16 +2233,20 @@ RE_SEARCH: /* Switch I/F Mode */ if (ptr[15]) { retval = ms_set_rw_reg_addr(chip, 0, 0, SystemParm, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_WRITE_REG(chip, PPBUF_BASE2, 0xFF, 0x88); RTSX_WRITE_REG(chip, PPBUF_BASE2 + 1, 0xFF, 0); retval = ms_transfer_tpc(chip, MS_TM_WRITE_BYTES, WRITE_REG, 1, NO_WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_WRITE_REG(chip, MS_CFG, 0x58 | MS_NO_CHECK_INT, MS_BUS_WIDTH_4 | PUSH_TIME_ODD | MS_NO_CHECK_INT); @@ -2021,24 +2275,32 @@ static int ms_init_l2p_tbl(struct rtsx_chip *chip) size = ms_card->segment_cnt * sizeof(struct zone_entry); ms_card->segment = vzalloc(size); - if (ms_card->segment == NULL) - TRACE_RET(chip, STATUS_FAIL); + if (ms_card->segment == NULL) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_read_page(chip, ms_card->boot_block, 1); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, INIT_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto INIT_FAIL; + } reg_addr = PPBUF_BASE2; for (i = 0; i < (((ms_card->total_block >> 9) * 10) + 1); i++) { int block_no; retval = rtsx_read_register(chip, reg_addr++, &val1); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, INIT_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto INIT_FAIL; + } retval = rtsx_read_register(chip, reg_addr++, &val2); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, INIT_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto INIT_FAIL; + } defect_block = ((u16)val1 << 8) | val2; if (defect_block == 0xFFFF) @@ -2201,8 +2463,10 @@ static int ms_build_l2p_tbl(struct rtsx_chip *chip, int seg_no) if (ms_card->segment == NULL) { retval = ms_init_l2p_tbl(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, retval); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return retval; + } } if (ms_card->segment[seg_no].build_flag) { @@ -2220,15 +2484,19 @@ static int ms_build_l2p_tbl(struct rtsx_chip *chip, int seg_no) if (segment->l2p_table == NULL) { segment->l2p_table = vmalloc(table_size * 2); - if (segment->l2p_table == NULL) - TRACE_GOTO(chip, BUILD_FAIL); + if (segment->l2p_table == NULL) { + rtsx_trace(chip); + goto BUILD_FAIL; + } } memset((u8 *)(segment->l2p_table), 0xff, table_size * 2); if (segment->free_table == NULL) { segment->free_table = vmalloc(MS_FREE_TABLE_CNT * 2); - if (segment->free_table == NULL) - TRACE_GOTO(chip, BUILD_FAIL); + if (segment->free_table == NULL) { + rtsx_trace(chip); + goto BUILD_FAIL; + } } memset((u8 *)(segment->free_table), 0xff, MS_FREE_TABLE_CNT * 2); @@ -2352,8 +2620,10 @@ static int ms_build_l2p_tbl(struct rtsx_chip *chip, int seg_no) return STATUS_SUCCESS; } retval = ms_init_page(chip, phy_blk, log_blk, 0, 1); - if (retval != STATUS_SUCCESS) - TRACE_GOTO(chip, BUILD_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + goto BUILD_FAIL; + } segment->l2p_table[idx] = phy_blk; if (seg_no == ms_card->segment_cnt - 1) { @@ -2383,14 +2653,18 @@ static int ms_build_l2p_tbl(struct rtsx_chip *chip, int seg_no) phy_blk = ms_get_unused_block(chip, 0); retval = ms_copy_page(chip, tmp_blk, phy_blk, log_blk, 0, ms_card->page_off + 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } segment->l2p_table[log_blk] = phy_blk; retval = ms_set_bad_block(chip, tmp_blk); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } } } @@ -2420,12 +2694,16 @@ int reset_ms_card(struct rtsx_chip *chip) memset(ms_card, 0, sizeof(struct ms_info)); retval = enable_card_clock(chip, MS_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = select_card(chip, MS_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_card->ms_type = 0; @@ -2433,24 +2711,31 @@ int reset_ms_card(struct rtsx_chip *chip) if (retval != STATUS_SUCCESS) { if (ms_card->check_ms_flow) { retval = reset_ms(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } retval = ms_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_MSPRO(ms_card)) { /* Build table for the last segment, * to check if L2P table block exists, erasing it */ retval = ms_build_l2p_tbl(chip, ms_card->total_block / 512 - 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } dev_dbg(rtsx_dev(chip), "ms_card->ms_type = 0x%x\n", ms_card->ms_type); @@ -2479,8 +2764,10 @@ static int mspro_set_rw_cmd(struct rtsx_chip *chip, if (retval == STATUS_SUCCESS) break; } - if (i == MS_MAX_RETRY_COUNT) - TRACE_RET(chip, STATUS_FAIL); + if (i == MS_MAX_RETRY_COUNT) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -2520,8 +2807,10 @@ static inline int ms_auto_tune_clock(struct rtsx_chip *chip) } retval = ms_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; } @@ -2570,8 +2859,10 @@ static int mspro_rw_multi_sector(struct scsi_cmnd *srb, } retval = ms_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (srb->sc_data_direction == DMA_FROM_DEVICE) trans_mode = MS_TM_AUTO_READ; @@ -2591,8 +2882,10 @@ static int mspro_rw_multi_sector(struct scsi_cmnd *srb, ms_card->total_sec_cnt = 0; if (val & MS_INT_BREQ) { retval = ms_send_cmd(chip, PRO_STOP, WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_write_register(chip, RBCTL, RB_FLUSH, RB_FLUSH); } @@ -2619,7 +2912,8 @@ static int mspro_rw_multi_sector(struct scsi_cmnd *srb, retval = mspro_set_rw_cmd(chip, start_sector, count, rw_cmd); if (retval != STATUS_SUCCESS) { ms_card->seq_mode = 0; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -2634,7 +2928,8 @@ static int mspro_rw_multi_sector(struct scsi_cmnd *srb, if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) { chip->rw_need_retry = 0; dev_dbg(rtsx_dev(chip), "No card exist, exit mspro_rw_multi_sector\n"); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (val & MS_INT_BREQ) @@ -2646,7 +2941,8 @@ static int mspro_rw_multi_sector(struct scsi_cmnd *srb, ms_auto_tune_clock(chip); } - TRACE_RET(chip, retval); + rtsx_trace(chip); + return retval; } if (ms_card->seq_mode) { @@ -2674,13 +2970,15 @@ static int mspro_read_format_progress(struct rtsx_chip *chip, retval = ms_switch_clock(chip); if (retval != STATUS_SUCCESS) { ms_card->format_status = FORMAT_FAIL; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = rtsx_read_register(chip, MS_TRANS_CFG, &tmp); if (retval != STATUS_SUCCESS) { ms_card->format_status = FORMAT_FAIL; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (!(tmp & MS_INT_BREQ)) { @@ -2689,7 +2987,8 @@ static int mspro_read_format_progress(struct rtsx_chip *chip, return STATUS_SUCCESS; } ms_card->format_status = FORMAT_FAIL; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (short_data_len >= 256) @@ -2701,14 +3000,16 @@ static int mspro_read_format_progress(struct rtsx_chip *chip, MS_NO_CHECK_INT); if (retval != STATUS_SUCCESS) { ms_card->format_status = FORMAT_FAIL; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = ms_read_bytes(chip, PRO_READ_SHORT_DATA, cnt, WAIT_INT, data, 8); if (retval != STATUS_SUCCESS) { ms_card->format_status = FORMAT_FAIL; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } total_progress = (data[0] << 24) | (data[1] << 16) | @@ -2733,7 +3034,8 @@ static int mspro_read_format_progress(struct rtsx_chip *chip, retval = rtsx_read_register(chip, MS_TRANS_CFG, &tmp); if (retval != STATUS_SUCCESS) { ms_card->format_status = FORMAT_FAIL; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (tmp & (MS_INT_CED | MS_INT_CMDNK | MS_INT_BREQ | MS_INT_ERR)) @@ -2745,17 +3047,20 @@ static int mspro_read_format_progress(struct rtsx_chip *chip, retval = rtsx_write_register(chip, MS_CFG, MS_NO_CHECK_INT, 0); if (retval != STATUS_SUCCESS) { ms_card->format_status = FORMAT_FAIL; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (i == 5000) { ms_card->format_status = FORMAT_FAIL; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (tmp & (MS_INT_CMDNK | MS_INT_ERR)) { ms_card->format_status = FORMAT_FAIL; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (tmp & MS_INT_CED) { @@ -2766,7 +3071,8 @@ static int mspro_read_format_progress(struct rtsx_chip *chip, } else { ms_card->format_status = FORMAT_FAIL; ms_card->pro_under_formatting = 0; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -2798,12 +3104,16 @@ int mspro_format(struct scsi_cmnd *srb, struct rtsx_chip *chip, u16 para; retval = ms_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_set_rw_reg_addr(chip, 0x00, 0x00, Pro_TPCParm, 0x01); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } memset(buf, 0, 2); switch (short_data_len) { @@ -2828,8 +3138,10 @@ int mspro_format(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (retval == STATUS_SUCCESS) break; } - if (i == MS_MAX_RETRY_COUNT) - TRACE_RET(chip, STATUS_FAIL); + if (i == MS_MAX_RETRY_COUNT) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (quick_format) para = 0x0000; @@ -2837,13 +3149,17 @@ int mspro_format(struct scsi_cmnd *srb, struct rtsx_chip *chip, para = 0x0001; retval = mspro_set_rw_cmd(chip, 0, para, PRO_FORMAT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_READ_REG(chip, MS_TRANS_CFG, &tmp); - if (tmp & (MS_INT_CMDNK | MS_INT_ERR)) - TRACE_RET(chip, STATUS_FAIL); + if (tmp & (MS_INT_CMDNK | MS_INT_ERR)) { + rtsx_trace(chip); + return STATUS_FAIL; + } if ((tmp & (MS_INT_BREQ | MS_INT_CED)) == MS_INT_BREQ) { ms_card->pro_under_formatting = 1; @@ -2860,7 +3176,8 @@ int mspro_format(struct scsi_cmnd *srb, struct rtsx_chip *chip, return STATUS_SUCCESS; } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } @@ -2879,14 +3196,17 @@ static int ms_read_multiple_pages(struct rtsx_chip *chip, u16 phy_blk, if (retval == STATUS_SUCCESS) { if ((extra[1] & 0x30) != 0x30) { ms_set_err_code(chip, MS_FLASH_READ_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, SystemParm, 6); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (CHK_MS4BIT(ms_card)) data[0] = 0x88; @@ -2905,14 +3225,18 @@ static int ms_read_multiple_pages(struct rtsx_chip *chip, u16 phy_blk, if (retval == STATUS_SUCCESS) break; } - if (i == MS_MAX_RETRY_COUNT) - TRACE_RET(chip, STATUS_FAIL); + if (i == MS_MAX_RETRY_COUNT) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_set_err_code(chip, MS_NO_ERROR); retval = ms_send_cmd(chip, BLOCK_READ, WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ptr = buf; @@ -2921,16 +3245,20 @@ static int ms_read_multiple_pages(struct rtsx_chip *chip, u16 phy_blk, if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) { ms_set_err_code(chip, MS_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (val & INT_REG_CMDNK) { ms_set_err_code(chip, MS_CMD_NK); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (val & INT_REG_ERR) { if (val & INT_REG_BREQ) { @@ -2943,34 +3271,42 @@ static int ms_read_multiple_pages(struct rtsx_chip *chip, u16 phy_blk, page_addr, extra, MS_EXTRA_SIZE); } ms_set_err_code(chip, MS_FLASH_READ_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } else { ms_set_err_code(chip, MS_FLASH_READ_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } else { if (!(val & INT_REG_BREQ)) { ms_set_err_code(chip, MS_BREQ_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } if (page_addr == (end_page - 1)) { if (!(val & INT_REG_CED)) { retval = ms_send_cmd(chip, BLOCK_END, WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (!(val & INT_REG_CED)) { ms_set_err_code(chip, MS_FLASH_READ_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } trans_cfg = NO_WAIT_INT; @@ -3003,19 +3339,22 @@ static int ms_read_multiple_pages(struct rtsx_chip *chip, u16 phy_blk, if (retval == -ETIMEDOUT) { ms_set_err_code(chip, MS_TO_ERROR); rtsx_clear_ms_error(chip); - TRACE_RET(chip, STATUS_TIMEDOUT); + rtsx_trace(chip); + return STATUS_TIMEDOUT; } retval = rtsx_read_register(chip, MS_TRANS_CFG, &val); if (retval != STATUS_SUCCESS) { ms_set_err_code(chip, MS_TO_ERROR); rtsx_clear_ms_error(chip); - TRACE_RET(chip, STATUS_TIMEDOUT); + rtsx_trace(chip); + return STATUS_TIMEDOUT; } if (val & (MS_CRC16_ERR | MS_RDY_TIMEOUT)) { ms_set_err_code(chip, MS_CRC16_ERROR); rtsx_clear_ms_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -3039,8 +3378,10 @@ static int ms_write_multiple_pages(struct rtsx_chip *chip, u16 old_blk, if (!start_page) { retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, SystemParm, 7); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (CHK_MS4BIT(ms_card)) data[0] = 0x88; @@ -3057,24 +3398,32 @@ static int ms_write_multiple_pages(struct rtsx_chip *chip, u16 old_blk, retval = ms_write_bytes(chip, WRITE_REG, 7, NO_WAIT_INT, data, 8); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_set_err_code(chip, MS_NO_ERROR); retval = ms_transfer_tpc(chip, MS_TM_READ_BYTES, GET_INT, 1, NO_WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, SystemParm, (6 + MS_EXTRA_SIZE)); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ms_set_err_code(chip, MS_NO_ERROR); @@ -3106,20 +3455,26 @@ static int ms_write_multiple_pages(struct rtsx_chip *chip, u16 old_blk, if (retval == STATUS_SUCCESS) break; } - if (i == MS_MAX_RETRY_COUNT) - TRACE_RET(chip, STATUS_FAIL); + if (i == MS_MAX_RETRY_COUNT) { + rtsx_trace(chip); + return STATUS_FAIL; + } for (i = 0; i < MS_MAX_RETRY_COUNT; i++) { retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT); if (retval == STATUS_SUCCESS) break; } - if (i == MS_MAX_RETRY_COUNT) - TRACE_RET(chip, STATUS_FAIL); + if (i == MS_MAX_RETRY_COUNT) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ptr = buf; for (page_addr = start_page; page_addr < end_page; page_addr++) { @@ -3127,20 +3482,24 @@ static int ms_write_multiple_pages(struct rtsx_chip *chip, u16 old_blk, if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) { ms_set_err_code(chip, MS_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (val & INT_REG_CMDNK) { ms_set_err_code(chip, MS_CMD_NK); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (val & INT_REG_ERR) { ms_set_err_code(chip, MS_FLASH_WRITE_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (!(val & INT_REG_BREQ)) { ms_set_err_code(chip, MS_BREQ_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } udelay(30); @@ -3171,34 +3530,43 @@ static int ms_write_multiple_pages(struct rtsx_chip *chip, u16 old_blk, ms_set_err_code(chip, MS_TO_ERROR); rtsx_clear_ms_error(chip); - if (retval == -ETIMEDOUT) - TRACE_RET(chip, STATUS_TIMEDOUT); - else - TRACE_RET(chip, STATUS_FAIL); + if (retval == -ETIMEDOUT) { + rtsx_trace(chip); + return STATUS_TIMEDOUT; + } + rtsx_trace(chip); + return STATUS_FAIL; } retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if ((end_page - start_page) == 1) { if (!(val & INT_REG_CED)) { ms_set_err_code(chip, MS_FLASH_WRITE_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } else { if (page_addr == (end_page - 1)) { if (!(val & INT_REG_CED)) { retval = ms_send_cmd(chip, BLOCK_END, WAIT_INT); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } if ((page_addr == (end_page - 1)) || @@ -3206,7 +3574,8 @@ static int ms_write_multiple_pages(struct rtsx_chip *chip, u16 old_blk, if (!(val & INT_REG_CED)) { ms_set_err_code(chip, MS_FLASH_WRITE_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } } @@ -3227,8 +3596,10 @@ static int ms_finish_write(struct rtsx_chip *chip, u16 old_blk, u16 new_blk, retval = ms_copy_page(chip, old_blk, new_blk, log_blk, page_off, ms_card->page_off + 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } seg_no = old_blk >> 9; @@ -3254,8 +3625,10 @@ static int ms_prepare_write(struct rtsx_chip *chip, u16 old_blk, u16 new_blk, if (start_page) { retval = ms_copy_page(chip, old_blk, new_blk, log_blk, 0, start_page); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -3270,8 +3643,10 @@ int ms_delay_write(struct rtsx_chip *chip) if (delay_write->delay_write_flag) { retval = ms_set_init_para(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } delay_write->delay_write_flag = 0; retval = ms_finish_write(chip, @@ -3279,8 +3654,10 @@ int ms_delay_write(struct rtsx_chip *chip) delay_write->new_phyblock, delay_write->logblock, delay_write->pageoff); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -3319,7 +3696,8 @@ static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rtsx_chip *chip, retval = ms_switch_clock(chip); if (retval != STATUS_SUCCESS) { ms_rw_fail(srb, chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } log_blk = (u16)(start_sector >> ms_card->block_shift); @@ -3335,7 +3713,8 @@ static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (retval != STATUS_SUCCESS) { chip->card_fail |= MS_CARD; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -3352,7 +3731,8 @@ static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } old_blk = delay_write->old_phyblock; new_blk = delay_write->new_phyblock; @@ -3367,7 +3747,8 @@ static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #endif old_blk = ms_get_l2p_tbl(chip, seg_no, @@ -3376,7 +3757,8 @@ static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rtsx_chip *chip, if ((old_blk == 0xFFFF) || (new_blk == 0xFFFF)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = ms_prepare_write(chip, old_blk, new_blk, @@ -3385,11 +3767,13 @@ static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #ifdef MS_DELAY_WRITE } @@ -3401,11 +3785,13 @@ static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #endif old_blk = ms_get_l2p_tbl(chip, seg_no, @@ -3413,7 +3799,8 @@ static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (old_blk == 0xFFFF) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -3446,10 +3833,12 @@ static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } ms_rw_fail(srb, chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (srb->sc_data_direction == DMA_TO_DEVICE) { @@ -3485,7 +3874,8 @@ static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rtsx_chip *chip, chip->card_fail |= MS_CARD; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -3493,14 +3883,16 @@ static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rtsx_chip *chip, log_blk - ms_start_idx[seg_no]); if (old_blk == 0xFFFF) { ms_rw_fail(srb, chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (srb->sc_data_direction == DMA_TO_DEVICE) { new_blk = ms_get_unused_block(chip, seg_no); if (new_blk == 0xFFFF) { ms_rw_fail(srb, chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -3525,11 +3917,13 @@ static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (detect_card_cd(chip, MS_CARD) != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } ms_rw_fail(srb, chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #endif } @@ -3591,12 +3985,16 @@ static int ms_poll_int(struct rtsx_chip *chip) rtsx_add_cmd(chip, CHECK_REG_CMD, MS_TRANS_CFG, MS_INT_CED, MS_INT_CED); retval = rtsx_send_cmd(chip, MS_CARD, 5000); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } val = *rtsx_get_cmd_data(chip); - if (val & MS_INT_ERR) - TRACE_RET(chip, STATUS_FAIL); + if (val & MS_INT_ERR) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -3659,12 +4057,15 @@ static int mg_send_ex_cmd(struct rtsx_chip *chip, u8 cmd, u8 entry_num) if (retval == STATUS_SUCCESS) break; } - if (i == MS_MAX_RETRY_COUNT) - TRACE_RET(chip, STATUS_FAIL); + if (i == MS_MAX_RETRY_COUNT) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (check_ms_err(chip)) { rtsx_clear_ms_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -3681,8 +4082,10 @@ static int mg_set_tpc_para_sub(struct rtsx_chip *chip, int type, else retval = ms_set_rw_reg_addr(chip, 0, 0, Pro_DataCount1, 6); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } buf[0] = 0; buf[1] = 0; @@ -3694,8 +4097,10 @@ static int mg_set_tpc_para_sub(struct rtsx_chip *chip, int type, } retval = ms_write_bytes(chip, PRO_WRITE_REG, (type == 0) ? 1 : 6, NO_WAIT_INT, buf, 6); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -3709,19 +4114,23 @@ int mg_set_leaf_id(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (scsi_bufflen(srb) < 12) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } ms_cleanup_work(chip); retval = ms_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = mg_send_ex_cmd(chip, MG_SET_LID, 0); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_ESTAB); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } memset(buf1, 0, 32); @@ -3733,12 +4142,14 @@ int mg_set_leaf_id(struct scsi_cmnd *srb, struct rtsx_chip *chip) buf1, 32); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_ESTAB); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (check_ms_err(chip)) { set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_ESTAB); rtsx_clear_ms_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -3754,12 +4165,16 @@ int mg_get_local_EKB(struct scsi_cmnd *srb, struct rtsx_chip *chip) ms_cleanup_work(chip); retval = ms_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } buf = kmalloc(1540, GFP_KERNEL); - if (!buf) - TRACE_RET(chip, STATUS_ERROR); + if (!buf) { + rtsx_trace(chip); + return STATUS_ERROR; + } buf[0] = 0x04; buf[1] = 0x1A; @@ -3769,7 +4184,8 @@ int mg_get_local_EKB(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = mg_send_ex_cmd(chip, MG_GET_LEKB, 0); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN); - TRACE_GOTO(chip, GetEKBFinish); + rtsx_trace(chip); + goto GetEKBFinish; } retval = ms_transfer_data(chip, MS_TM_AUTO_READ, PRO_READ_LONG_DATA, @@ -3777,12 +4193,14 @@ int mg_get_local_EKB(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN); rtsx_clear_ms_error(chip); - TRACE_GOTO(chip, GetEKBFinish); + rtsx_trace(chip); + goto GetEKBFinish; } if (check_ms_err(chip)) { set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN); rtsx_clear_ms_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } bufflen = min_t(int, 1052, scsi_bufflen(srb)); @@ -3805,25 +4223,30 @@ int mg_chg(struct scsi_cmnd *srb, struct rtsx_chip *chip) ms_cleanup_work(chip); retval = ms_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = mg_send_ex_cmd(chip, MG_GET_ID, 0); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = ms_read_bytes(chip, PRO_READ_SHORT_DATA, 32, WAIT_INT, buf, 32); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (check_ms_err(chip)) { set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM); rtsx_clear_ms_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } memcpy(ms_card->magic_gate_id, buf, 16); @@ -3832,14 +4255,16 @@ int mg_chg(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = ms_poll_int(chip); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #endif retval = mg_send_ex_cmd(chip, MG_SET_RD, 0); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } bufflen = min_t(int, 12, scsi_bufflen(srb)); @@ -3855,12 +4280,14 @@ int mg_chg(struct scsi_cmnd *srb, struct rtsx_chip *chip) 32, WAIT_INT, buf, 32); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (check_ms_err(chip)) { set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM); rtsx_clear_ms_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } ms_card->mg_auth = 0; @@ -3879,25 +4306,30 @@ int mg_get_rsp_chg(struct scsi_cmnd *srb, struct rtsx_chip *chip) ms_cleanup_work(chip); retval = ms_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = mg_send_ex_cmd(chip, MG_MAKE_RMS, 0); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = ms_read_bytes(chip, PRO_READ_SHORT_DATA, 32, WAIT_INT, buf1, 32); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (check_ms_err(chip)) { set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN); rtsx_clear_ms_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } buf2[0] = 0x00; @@ -3915,7 +4347,8 @@ int mg_get_rsp_chg(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = ms_poll_int(chip); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #endif @@ -3934,13 +4367,16 @@ int mg_rsp(struct scsi_cmnd *srb, struct rtsx_chip *chip) ms_cleanup_work(chip); retval = ms_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = mg_send_ex_cmd(chip, MG_MAKE_KSE, 0); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } bufflen = min_t(int, 12, scsi_bufflen(srb)); @@ -3956,12 +4392,14 @@ int mg_rsp(struct scsi_cmnd *srb, struct rtsx_chip *chip) buf, 32); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (check_ms_err(chip)) { set_sense_type(chip, lun, SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN); rtsx_clear_ms_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } ms_card->mg_auth = 1; @@ -3980,12 +4418,16 @@ int mg_get_ICV(struct scsi_cmnd *srb, struct rtsx_chip *chip) ms_cleanup_work(chip); retval = ms_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } buf = kmalloc(1028, GFP_KERNEL); - if (!buf) - TRACE_RET(chip, STATUS_ERROR); + if (!buf) { + rtsx_trace(chip); + return STATUS_ERROR; + } buf[0] = 0x04; buf[1] = 0x02; @@ -3995,7 +4437,8 @@ int mg_get_ICV(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = mg_send_ex_cmd(chip, MG_GET_IBD, ms_card->mg_entry_num); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_GOTO(chip, GetICVFinish); + rtsx_trace(chip); + goto GetICVFinish; } retval = ms_transfer_data(chip, MS_TM_AUTO_READ, PRO_READ_LONG_DATA, @@ -4003,12 +4446,14 @@ int mg_get_ICV(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); rtsx_clear_ms_error(chip); - TRACE_GOTO(chip, GetICVFinish); + rtsx_trace(chip); + goto GetICVFinish; } if (check_ms_err(chip)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); rtsx_clear_ms_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } bufflen = min_t(int, 1028, scsi_bufflen(srb)); @@ -4033,12 +4478,16 @@ int mg_set_ICV(struct scsi_cmnd *srb, struct rtsx_chip *chip) ms_cleanup_work(chip); retval = ms_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } buf = kmalloc(1028, GFP_KERNEL); - if (!buf) - TRACE_RET(chip, STATUS_ERROR); + if (!buf) { + rtsx_trace(chip); + return STATUS_ERROR; + } bufflen = min_t(int, 1028, scsi_bufflen(srb)); rtsx_stor_get_xfer_buf(buf, bufflen, srb); @@ -4055,7 +4504,8 @@ int mg_set_ICV(struct scsi_cmnd *srb, struct rtsx_chip *chip) } else { set_sense_type(chip, lun, SENSE_TYPE_MG_WRITE_ERR); } - TRACE_GOTO(chip, SetICVFinish); + rtsx_trace(chip); + goto SetICVFinish; } #ifdef MG_SET_ICV_SLOW @@ -4094,7 +4544,8 @@ int mg_set_ICV(struct scsi_cmnd *srb, struct rtsx_chip *chip) SENSE_TYPE_MG_WRITE_ERR); } retval = STATUS_FAIL; - TRACE_GOTO(chip, SetICVFinish); + rtsx_trace(chip); + goto SetICVFinish; } } #else @@ -4112,7 +4563,8 @@ int mg_set_ICV(struct scsi_cmnd *srb, struct rtsx_chip *chip) } else { set_sense_type(chip, lun, SENSE_TYPE_MG_WRITE_ERR); } - TRACE_GOTO(chip, SetICVFinish); + rtsx_trace(chip); + goto SetICVFinish; } #endif @@ -4152,13 +4604,17 @@ int ms_power_off_card3v3(struct rtsx_chip *chip) int retval; retval = disable_card_clock(chip, MS_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 = ms_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_MS_PULL_CTL_BIT | 0x20, FPGA_MS_PULL_CTL_BIT); @@ -4166,8 +4622,10 @@ int ms_power_off_card3v3(struct rtsx_chip *chip) RTSX_WRITE_REG(chip, CARD_OE, MS_OUTPUT_EN, 0); if (!chip->ft2_fast_mode) { retval = card_power_off(chip, MS_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -4195,8 +4653,10 @@ int release_ms_card(struct rtsx_chip *chip) #endif retval = ms_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; } diff --git a/drivers/staging/rts5208/rtsx.c b/drivers/staging/rts5208/rtsx.c index c482a6ac26ba..d64b6ed9c0c9 100644 --- a/drivers/staging/rts5208/rtsx.c +++ b/drivers/staging/rts5208/rtsx.c @@ -26,12 +26,6 @@ #include #include "rtsx.h" -#include "rtsx_chip.h" -#include "rtsx_transport.h" -#include "rtsx_scsi.h" -#include "rtsx_card.h" -#include "general.h" - #include "ms.h" #include "sd.h" #include "xd.h" diff --git a/drivers/staging/rts5208/rtsx.h b/drivers/staging/rts5208/rtsx.h index 9e6ecb7457b5..262441bcfc41 100644 --- a/drivers/staging/rts5208/rtsx.h +++ b/drivers/staging/rts5208/rtsx.h @@ -46,9 +46,6 @@ #include #include -#include "trace.h" -#include "general.h" - #define CR_DRIVER_NAME "rts5208" #define pci_get_bus_and_slot(bus, devfn) \ @@ -181,4 +178,14 @@ enum xfer_buf_dir {TO_XFER_BUF, FROM_XFER_BUF}; int rtsx_read_pci_cfg_byte(u8 bus, u8 dev, u8 func, u8 offset, u8 *val); +#define _MSG_TRACE + +#include "trace.h" +#include "rtsx_chip.h" +#include "rtsx_transport.h" +#include "rtsx_scsi.h" +#include "rtsx_card.h" +#include "rtsx_sys.h" +#include "general.h" + #endif /* __REALTEK_RTSX_H */ diff --git a/drivers/staging/rts5208/rtsx_card.c b/drivers/staging/rts5208/rtsx_card.c index b4595ab3f02b..d7ca44f61447 100644 --- a/drivers/staging/rts5208/rtsx_card.c +++ b/drivers/staging/rts5208/rtsx_card.c @@ -27,13 +27,6 @@ #include #include "rtsx.h" -#include "rtsx_transport.h" -#include "rtsx_scsi.h" -#include "rtsx_card.h" - -#include "rtsx_sys.h" -#include "general.h" - #include "sd.h" #include "xd.h" #include "ms.h" @@ -657,8 +650,10 @@ int switch_ssc_clock(struct rtsx_chip *chip, int clk) dev_dbg(rtsx_dev(chip), "Switch SSC clock to %dMHz (cur_clk = %d)\n", clk, chip->cur_clk); - if ((clk <= 2) || (N > max_N)) - TRACE_RET(chip, STATUS_FAIL); + if ((clk <= 2) || (N > max_N)) { + rtsx_trace(chip); + return STATUS_FAIL; + } mcu_cnt = (u8)(125/clk + 3); if (mcu_cnt > 7) @@ -697,8 +692,10 @@ int switch_ssc_clock(struct rtsx_chip *chip, int clk) } retval = rtsx_send_cmd(chip, 0, WAIT_TIME); - if (retval < 0) - TRACE_RET(chip, STATUS_ERROR); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_ERROR; + } udelay(10); RTSX_WRITE_REG(chip, CLK_CTL, CLK_LOW_FREQ, 0); @@ -790,7 +787,8 @@ int switch_normal_clock(struct rtsx_chip *chip, int clk) default: dev_dbg(rtsx_dev(chip), "Try to switch to an illegal clock (%d)\n", clk); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } RTSX_WRITE_REG(chip, CLK_CTL, 0xFF, CLK_LOW_FREQ); @@ -893,8 +891,10 @@ int card_power_on(struct rtsx_chip *chip, u8 card) rtsx_add_cmd(chip, WRITE_REG_CMD, CARD_PWR_CTL, mask, val1); retval = rtsx_send_cmd(chip, 0, 100); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } udelay(chip->pmos_pwr_on_interval); @@ -902,8 +902,10 @@ int card_power_on(struct rtsx_chip *chip, u8 card) rtsx_add_cmd(chip, WRITE_REG_CMD, CARD_PWR_CTL, mask, val2); retval = rtsx_send_cmd(chip, 0, 100); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -932,8 +934,10 @@ int card_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, unsigned int lun = SCSI_LUN(srb); int i; - if (chip->rw_card[lun] == NULL) - TRACE_RET(chip, STATUS_FAIL); + if (chip->rw_card[lun] == NULL) { + rtsx_trace(chip); + return STATUS_FAIL; + } for (i = 0; i < 3; i++) { chip->rw_need_retry = 0; @@ -942,11 +946,14 @@ int card_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (retval != STATUS_SUCCESS) { if (rtsx_check_chip_exist(chip) != STATUS_SUCCESS) { rtsx_release_chip(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (detect_card_cd(chip, chip->cur_card) != - STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (!chip->rw_need_retry) { dev_dbg(rtsx_dev(chip), "RW fail, but no need to retry\n"); @@ -975,8 +982,10 @@ int card_share_mode(struct rtsx_chip *chip, int card) value = CARD_SHARE_48_MS; else if (card == XD_CARD) value = CARD_SHARE_48_XD; - else - TRACE_RET(chip, STATUS_FAIL); + else { + rtsx_trace(chip); + return STATUS_FAIL; + } } else if (CHECK_PID(chip, 0x5288)) { mask = 0x03; @@ -986,11 +995,14 @@ int card_share_mode(struct rtsx_chip *chip, int card) value = CARD_SHARE_BAROSSA_MS; else if (card == XD_CARD) value = CARD_SHARE_BAROSSA_XD; - else - TRACE_RET(chip, STATUS_FAIL); + else { + rtsx_trace(chip); + return STATUS_FAIL; + } } else { - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } RTSX_WRITE_REG(chip, CARD_SHARE_MODE, mask, value); @@ -1014,15 +1026,19 @@ int select_card(struct rtsx_chip *chip, int card) mod = XD_MOD_SEL; else if (card == SPI_CARD) mod = SPI_MOD_SEL; - else - TRACE_RET(chip, STATUS_FAIL); + else { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_WRITE_REG(chip, CARD_SELECT, 0x07, mod); chip->cur_card = card; retval = card_share_mode(chip, card); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -1067,12 +1083,15 @@ int detect_card_cd(struct rtsx_chip *chip, int card) card_cd = XD_EXIST; } else { dev_dbg(rtsx_dev(chip), "Wrong card type: 0x%x\n", card); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } status = rtsx_readl(chip, RTSX_BIPR); - if (!(status & card_cd)) - TRACE_RET(chip, STATUS_FAIL); + if (!(status & card_cd)) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } diff --git a/drivers/staging/rts5208/rtsx_chip.c b/drivers/staging/rts5208/rtsx_chip.c index 35fa19d8b7a2..a8feee846dd3 100644 --- a/drivers/staging/rts5208/rtsx_chip.c +++ b/drivers/staging/rts5208/rtsx_chip.c @@ -27,13 +27,6 @@ #include #include "rtsx.h" -#include "rtsx_transport.h" -#include "rtsx_scsi.h" -#include "rtsx_card.h" -#include "rtsx_chip.h" -#include "rtsx_sys.h" -#include "general.h" - #include "sd.h" #include "xd.h" #include "ms.h" @@ -198,15 +191,19 @@ static int rtsx_pre_handle_sdio_new(struct rtsx_chip *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 { RTSX_WRITE_REG(chip, FPGA_PULL_CTL, FPGA_SD_PULL_CTL_BIT | 0x20, 0); } 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; + } /* Enable sdio_bus_auto_switch */ if (CHECK_PID(chip, 0x5288)) @@ -237,8 +234,10 @@ static int rtsx_reset_aspm(struct rtsx_chip *chip) ret = rtsx_write_cfg_dw(chip, 2, 0xC0, 0xFF, chip->aspm_l0s_l1_en); - if (ret != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (ret != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -246,16 +245,20 @@ static int rtsx_reset_aspm(struct rtsx_chip *chip) if (CHECK_PID(chip, 0x5208)) RTSX_WRITE_REG(chip, ASPM_FORCE_CTL, 0xFF, 0x3F); ret = rtsx_write_config_byte(chip, LCTLR, chip->aspm_l0s_l1_en); - if (ret != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (ret != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } chip->aspm_level[0] = chip->aspm_l0s_l1_en; if (CHK_SDIO_EXIST(chip)) { chip->aspm_level[1] = chip->aspm_l0s_l1_en; ret = rtsx_write_cfg_dw(chip, CHECK_PID(chip, 0x5288) ? 2 : 1, 0xC0, 0xFF, chip->aspm_l0s_l1_en); - if (ret != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (ret != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } chip->aspm_enabled = 1; @@ -283,23 +286,31 @@ static int rtsx_enable_pcie_intr(struct rtsx_chip *chip) u16 reg; ret = rtsx_read_phy_register(chip, 0x00, ®); - if (ret != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (ret != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } reg &= 0xFE7F; reg |= 0x80; ret = rtsx_write_phy_register(chip, 0x00, reg); - if (ret != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (ret != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } ret = rtsx_read_phy_register(chip, 0x1C, ®); - if (ret != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (ret != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } reg &= 0xFFF7; ret = rtsx_write_phy_register(chip, 0x1C, reg); - if (ret != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (ret != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } if (chip->driver_first_load && (chip->ic_version < IC_VER_C)) @@ -371,41 +382,55 @@ int rtsx_reset_chip(struct rtsx_chip *chip) /* Enable ASPM */ if (chip->aspm_l0s_l1_en) { retval = rtsx_reset_aspm(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else { if (chip->asic_code && CHECK_PID(chip, 0x5208)) { retval = rtsx_write_phy_register(chip, 0x07, 0x0129); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } retval = rtsx_write_config_byte(chip, LCTLR, chip->aspm_l0s_l1_en); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } retval = rtsx_write_config_byte(chip, 0x81, 1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (CHK_SDIO_EXIST(chip)) { retval = rtsx_write_cfg_dw(chip, CHECK_PID(chip, 0x5288) ? 2 : 1, 0xC0, 0xFF00, 0x0100); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } if (CHECK_PID(chip, 0x5288) && !CHK_SDIO_EXIST(chip)) { retval = rtsx_write_cfg_dw(chip, 2, 0xC0, 0xFFFF, 0x0103); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = rtsx_write_cfg_dw(chip, 2, 0x84, 0xFF, 0x03); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } RTSX_WRITE_REG(chip, IRQSTAT0, LINK_RDY_INT, LINK_RDY_INT); @@ -413,8 +438,10 @@ int rtsx_reset_chip(struct rtsx_chip *chip) RTSX_WRITE_REG(chip, PERST_GLITCH_WIDTH, 0xFF, 0x80); retval = rtsx_enable_pcie_intr(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } chip->need_reset = 0; @@ -436,8 +463,10 @@ int rtsx_reset_chip(struct rtsx_chip *chip) #else /* HW_AUTO_SWITCH_SD_BUS */ retval = rtsx_pre_handle_sdio_old(chip); #endif /* HW_AUTO_SWITCH_SD_BUS */ - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else { chip->sd_io = 0; @@ -477,8 +506,10 @@ nextcard: if (chip->asic_code && CHECK_PID(chip, 0x5208)) { retval = rtsx_clr_phy_reg_bit(chip, 0x1C, 2); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } if (chip->ft2_fast_mode) { @@ -545,8 +576,10 @@ static int rts5208_init(struct rtsx_chip *chip) if (chip->asic_code) { retval = rtsx_read_phy_register(chip, 0x1C, ®); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } dev_dbg(rtsx_dev(chip), "Value of phy register 0x1C is 0x%x\n", reg); @@ -605,8 +638,10 @@ static int rts5288_init(struct rtsx_chip *chip) chip->hw_bypass_sd = val & 0x10 ? 1 : 0; retval = rtsx_read_cfg_dw(chip, 0, 0x718, &lval); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } max_func = (u8)((lval >> 29) & 0x07); dev_dbg(rtsx_dev(chip), "Max function number: %d\n", max_func); @@ -703,13 +738,17 @@ int rtsx_init_chip(struct rtsx_chip *chip) if (CHECK_PID(chip, 0x5208)) { retval = rts5208_init(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else if (CHECK_PID(chip, 0x5288)) { retval = rts5288_init(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } if (chip->ss_en == 2) @@ -756,8 +795,10 @@ int rtsx_init_chip(struct rtsx_chip *chip) } retval = rtsx_reset_chip(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -1155,14 +1196,17 @@ int rtsx_write_register(struct rtsx_chip *chip, u16 addr, u8 mask, u8 data) for (i = 0; i < MAX_RW_REG_CNT; i++) { val = rtsx_readl(chip, RTSX_HAIMR); if ((val & (1 << 31)) == 0) { - if (data != (u8)val) - TRACE_RET(chip, STATUS_FAIL); + if (data != (u8)val) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } } - TRACE_RET(chip, STATUS_TIMEDOUT); + rtsx_trace(chip); + return STATUS_TIMEDOUT; } int rtsx_read_register(struct rtsx_chip *chip, u16 addr, u8 *data) @@ -1183,8 +1227,10 @@ int rtsx_read_register(struct rtsx_chip *chip, u16 addr, u8 *data) break; } - if (i >= MAX_RW_REG_CNT) - TRACE_RET(chip, STATUS_TIMEDOUT); + if (i >= MAX_RW_REG_CNT) { + rtsx_trace(chip); + return STATUS_TIMEDOUT; + } if (data) *data = (u8)(val & 0xFF); @@ -1261,8 +1307,10 @@ int rtsx_write_cfg_seq(struct rtsx_chip *chip, u8 func, u16 addr, u8 *buf, int dw_len, i, j; int retval; - if (!buf) - TRACE_RET(chip, STATUS_NOMEM); + if (!buf) { + rtsx_trace(chip); + return STATUS_NOMEM; + } if ((len + offset) % 4) dw_len = (len + offset) / 4 + 1; @@ -1272,13 +1320,16 @@ int rtsx_write_cfg_seq(struct rtsx_chip *chip, u8 func, u16 addr, u8 *buf, dev_dbg(rtsx_dev(chip), "dw_len = %d\n", dw_len); data = vzalloc(dw_len * 4); - if (!data) - TRACE_RET(chip, STATUS_NOMEM); + if (!data) { + rtsx_trace(chip); + return STATUS_NOMEM; + } mask = vzalloc(dw_len * 4); if (!mask) { vfree(data); - TRACE_RET(chip, STATUS_NOMEM); + rtsx_trace(chip); + return STATUS_NOMEM; } j = 0; @@ -1302,7 +1353,8 @@ int rtsx_write_cfg_seq(struct rtsx_chip *chip, u8 func, u16 addr, u8 *buf, if (retval != STATUS_SUCCESS) { vfree(data); vfree(mask); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1329,15 +1381,18 @@ int rtsx_read_cfg_seq(struct rtsx_chip *chip, u8 func, u16 addr, u8 *buf, dev_dbg(rtsx_dev(chip), "dw_len = %d\n", dw_len); data = vmalloc(dw_len * 4); - if (!data) - TRACE_RET(chip, STATUS_NOMEM); + if (!data) { + rtsx_trace(chip); + return STATUS_NOMEM; + } for (i = 0; i < dw_len; i++) { retval = rtsx_read_cfg_dw(chip, func, aligned_addr + i * 4, data + i); if (retval != STATUS_SUCCESS) { vfree(data); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1377,8 +1432,10 @@ int rtsx_write_phy_register(struct rtsx_chip *chip, u8 addr, u16 val) } } - if (!finished) - TRACE_RET(chip, STATUS_FAIL); + if (!finished) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -1401,8 +1458,10 @@ int rtsx_read_phy_register(struct rtsx_chip *chip, u8 addr, u16 *val) } } - if (!finished) - TRACE_RET(chip, STATUS_FAIL); + if (!finished) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_READ_REG(chip, PHYDATA0, &tmp); data = tmp; @@ -1429,8 +1488,10 @@ int rtsx_read_efuse(struct rtsx_chip *chip, u8 addr, u8 *val) udelay(1); } - if (data & 0x80) - TRACE_RET(chip, STATUS_TIMEDOUT); + if (data & 0x80) { + rtsx_trace(chip); + return STATUS_TIMEDOUT; + } RTSX_READ_REG(chip, EFUSE_DATA, &data); if (val) @@ -1461,8 +1522,10 @@ int rtsx_write_efuse(struct rtsx_chip *chip, u8 addr, u8 val) wait_timeout(3); } - if (data & 0x80) - TRACE_RET(chip, STATUS_TIMEDOUT); + if (data & 0x80) { + rtsx_trace(chip); + return STATUS_TIMEDOUT; + } wait_timeout(5); } @@ -1476,14 +1539,18 @@ int rtsx_clr_phy_reg_bit(struct rtsx_chip *chip, u8 reg, u8 bit) u16 value; retval = rtsx_read_phy_register(chip, reg, &value); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (value & (1 << bit)) { value &= ~(1 << bit); retval = rtsx_write_phy_register(chip, reg, value); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -1495,14 +1562,18 @@ int rtsx_set_phy_reg_bit(struct rtsx_chip *chip, u8 reg, u8 bit) u16 value; retval = rtsx_read_phy_register(chip, reg, &value); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if ((value & (1 << bit)) == 0) { value |= (1 << bit); retval = rtsx_write_phy_register(chip, reg, value); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -1818,8 +1889,10 @@ int rtsx_read_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len) u16 reg_addr; u8 *ptr; - if (!buf) - TRACE_RET(chip, STATUS_ERROR); + if (!buf) { + rtsx_trace(chip); + return STATUS_ERROR; + } ptr = buf; reg_addr = PPBUF_BASE2; @@ -1830,8 +1903,10 @@ int rtsx_read_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len) rtsx_add_cmd(chip, READ_REG_CMD, reg_addr++, 0, 0); retval = rtsx_send_cmd(chip, 0, 250); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } memcpy(ptr, rtsx_get_cmd_data(chip), 256); ptr += 256; @@ -1844,8 +1919,10 @@ int rtsx_read_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len) rtsx_add_cmd(chip, READ_REG_CMD, reg_addr++, 0, 0); retval = rtsx_send_cmd(chip, 0, 250); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } } memcpy(ptr, rtsx_get_cmd_data(chip), buf_len%256); @@ -1860,8 +1937,10 @@ int rtsx_write_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len) u16 reg_addr; u8 *ptr; - if (!buf) - TRACE_RET(chip, STATUS_ERROR); + if (!buf) { + rtsx_trace(chip); + return STATUS_ERROR; + } ptr = buf; reg_addr = PPBUF_BASE2; @@ -1875,8 +1954,10 @@ int rtsx_write_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len) } retval = rtsx_send_cmd(chip, 0, 250); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } } if (buf_len%256) { @@ -1889,8 +1970,10 @@ int rtsx_write_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len) } retval = rtsx_send_cmd(chip, 0, 250); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -1898,8 +1981,10 @@ int rtsx_write_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len) int rtsx_check_chip_exist(struct rtsx_chip *chip) { - if (rtsx_readl(chip, 0) == 0xFFFFFFFF) - TRACE_RET(chip, STATUS_FAIL); + if (rtsx_readl(chip, 0) == 0xFFFFFFFF) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -1922,8 +2007,10 @@ int rtsx_force_power_on(struct rtsx_chip *chip, u8 ctl) if (mask) { retval = rtsx_write_register(chip, FPDCTL, mask, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (CHECK_PID(chip, 0x5288)) wait_timeout(200); @@ -1951,8 +2038,10 @@ int rtsx_force_power_down(struct rtsx_chip *chip, u8 ctl) if (mask) { val = mask; retval = rtsx_write_register(chip, FPDCTL, mask, val); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; diff --git a/drivers/staging/rts5208/rtsx_chip.h b/drivers/staging/rts5208/rtsx_chip.h index feac98661cec..93fd7b286f49 100644 --- a/drivers/staging/rts5208/rtsx_chip.h +++ b/drivers/staging/rts5208/rtsx_chip.h @@ -989,19 +989,21 @@ int rtsx_write_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len); int rtsx_check_chip_exist(struct rtsx_chip *chip); #define RTSX_WRITE_REG(chip, addr, mask, data) \ - do { \ - int retval = rtsx_write_register((chip), (addr), (mask), (data)); \ - if (retval != STATUS_SUCCESS) { \ - TRACE_RET((chip), retval); \ - } \ - } while (0) +do { \ + int retval = rtsx_write_register(chip, addr, mask, data); \ + if (retval != STATUS_SUCCESS) { \ + rtsx_trace(chip); \ + return retval; \ + } \ +} while (0) #define RTSX_READ_REG(chip, addr, data) \ - do { \ - int retval = rtsx_read_register((chip), (addr), (data)); \ - if (retval != STATUS_SUCCESS) { \ - TRACE_RET((chip), retval); \ - } \ - } while (0) +do { \ + int retval = rtsx_read_register(chip, addr, data); \ + if (retval != STATUS_SUCCESS) { \ + rtsx_trace(chip); \ + return retval; \ + } \ +} while (0) #endif /* __REALTEK_RTSX_CHIP_H */ diff --git a/drivers/staging/rts5208/rtsx_scsi.c b/drivers/staging/rts5208/rtsx_scsi.c index 98f102b78e6d..8a5d6a8e780f 100644 --- a/drivers/staging/rts5208/rtsx_scsi.c +++ b/drivers/staging/rts5208/rtsx_scsi.c @@ -26,11 +26,6 @@ #include #include "rtsx.h" -#include "rtsx_transport.h" -#include "rtsx_sys.h" -#include "rtsx_card.h" -#include "rtsx_chip.h" -#include "rtsx_scsi.h" #include "sd.h" #include "ms.h" #include "spi.h" @@ -512,8 +507,10 @@ static int inquiry(struct scsi_cmnd *srb, struct rtsx_chip *chip) } buf = vmalloc(scsi_bufflen(srb)); - if (buf == NULL) - TRACE_RET(chip, TRANSPORT_ERROR); + if (buf == NULL) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } #ifdef SUPPORT_MAGIC_GATE if ((chip->mspro_formatter_enable) && @@ -587,12 +584,14 @@ static int start_stop_unit(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (check_card_ready(chip, lun)) return TRANSPORT_GOOD; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; break; } - TRACE_RET(chip, TRANSPORT_ERROR); + rtsx_trace(chip); + return TRANSPORT_ERROR; } @@ -607,7 +606,8 @@ static int allow_medium_removal(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (prevent) { set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } return TRANSPORT_GOOD; @@ -644,8 +644,10 @@ static int request_sense(struct scsi_cmnd *srb, struct rtsx_chip *chip) } buf = vmalloc(scsi_bufflen(srb)); - if (buf == NULL) - TRACE_RET(chip, TRANSPORT_ERROR); + if (buf == NULL) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } tmp = (unsigned char *)sense; memcpy(buf, tmp, scsi_bufflen(srb)); @@ -765,7 +767,8 @@ static int mode_sense(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!check_card_ready(chip, lun)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); scsi_set_resid(srb, scsi_bufflen(srb)); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } #endif @@ -789,8 +792,10 @@ static int mode_sense(struct scsi_cmnd *srb, struct rtsx_chip *chip) #endif buf = kmalloc(dataSize, GFP_KERNEL); - if (buf == NULL) - TRACE_RET(chip, TRANSPORT_ERROR); + if (buf == NULL) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } pageCode = srb->cmnd[2] & 0x3f; @@ -869,7 +874,8 @@ static int read_write(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!check_card_ready(chip, lun) || (get_card_size(chip, lun) == 0)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (!(CHK_BIT(chip->lun_mc, lun))) { @@ -885,7 +891,8 @@ static int read_write(struct scsi_cmnd *srb, struct rtsx_chip *chip) */ dev_dbg(rtsx_dev(chip), "SD card being erased!\n"); set_sense_type(chip, lun, SENSE_TYPE_MEDIA_READ_FORBIDDEN); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (get_lun_card(chip, lun) == SD_CARD) { @@ -893,7 +900,8 @@ static int read_write(struct scsi_cmnd *srb, struct rtsx_chip *chip) dev_dbg(rtsx_dev(chip), "SD card locked!\n"); set_sense_type(chip, lun, SENSE_TYPE_MEDIA_READ_FORBIDDEN); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } #endif @@ -916,7 +924,8 @@ static int read_write(struct scsi_cmnd *srb, struct rtsx_chip *chip) sec_cnt = ((u16)(srb->cmnd[9]) << 8) | srb->cmnd[10]; } else { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } /* In some test, we will receive a start_sec like 0xFFFFFFFF. @@ -926,7 +935,8 @@ static int read_write(struct scsi_cmnd *srb, struct rtsx_chip *chip) if ((start_sec > get_card_size(chip, lun)) || ((start_sec + sec_cnt) > get_card_size(chip, lun))) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_LBA_OVER_RANGE); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (sec_cnt == 0) { @@ -942,7 +952,8 @@ static int read_write(struct scsi_cmnd *srb, struct rtsx_chip *chip) else set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (srb->sc_data_direction == DMA_TO_DEVICE) { @@ -950,7 +961,8 @@ static int read_write(struct scsi_cmnd *srb, struct rtsx_chip *chip) dev_dbg(rtsx_dev(chip), "Write protected card!\n"); set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_PROTECT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } @@ -969,7 +981,8 @@ static int read_write(struct scsi_cmnd *srb, struct rtsx_chip *chip) SENSE_TYPE_MEDIA_WRITE_ERR); } retval = TRANSPORT_FAILED; - TRACE_GOTO(chip, Exit); + rtsx_trace(chip); + goto Exit; } else { chip->rw_fail_cnt[lun] = 0; retval = TRANSPORT_GOOD; @@ -994,15 +1007,18 @@ static int read_format_capacity(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!check_card_ready(chip, lun)) { if (!chip->mspro_formatter_enable) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } buf_len = (scsi_bufflen(srb) > 12) ? 0x14 : 12; buf = kmalloc(buf_len, GFP_KERNEL); - if (buf == NULL) - TRACE_RET(chip, TRANSPORT_ERROR); + if (buf == NULL) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } buf[i++] = 0; buf[i++] = 0; @@ -1067,7 +1083,8 @@ static int read_capacity(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!check_card_ready(chip, lun)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (!(CHK_BIT(chip->lun_mc, lun))) { @@ -1077,8 +1094,10 @@ static int read_capacity(struct scsi_cmnd *srb, struct rtsx_chip *chip) } buf = kmalloc(8, GFP_KERNEL); - if (buf == NULL) - TRACE_RET(chip, TRANSPORT_ERROR); + if (buf == NULL) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } card_size = get_card_size(chip, lun); buf[0] = (unsigned char)((card_size - 1) >> 24); @@ -1116,15 +1135,18 @@ static int read_eeprom(struct scsi_cmnd *srb, struct rtsx_chip *chip) len = ((u16)srb->cmnd[4] << 8) | srb->cmnd[5]; buf = vmalloc(len); - if (!buf) - TRACE_RET(chip, TRANSPORT_ERROR); + if (!buf) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } retval = rtsx_force_power_on(chip, SSC_PDCTL); if (retval != STATUS_SUCCESS) { vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } for (i = 0; i < len; i++) { @@ -1133,7 +1155,8 @@ static int read_eeprom(struct scsi_cmnd *srb, struct rtsx_chip *chip) vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } @@ -1165,7 +1188,8 @@ static int write_eeprom(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = rtsx_force_power_on(chip, SSC_PDCTL); if (retval != STATUS_SUCCESS) { set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (len == 511) { @@ -1173,14 +1197,17 @@ static int write_eeprom(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (retval != STATUS_SUCCESS) { set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } else { len = (unsigned short)min_t(unsigned int, scsi_bufflen(srb), len); buf = vmalloc(len); - if (buf == NULL) - TRACE_RET(chip, TRANSPORT_ERROR); + if (buf == NULL) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } rtsx_stor_get_xfer_buf(buf, len, srb); scsi_set_resid(srb, scsi_bufflen(srb) - len); @@ -1191,7 +1218,8 @@ static int write_eeprom(struct scsi_cmnd *srb, struct rtsx_chip *chip) vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } @@ -1221,18 +1249,22 @@ static int read_mem(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (addr < 0xFC00) { set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } buf = vmalloc(len); - if (!buf) - TRACE_RET(chip, TRANSPORT_ERROR); + if (!buf) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } retval = rtsx_force_power_on(chip, SSC_PDCTL); if (retval != STATUS_SUCCESS) { vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } for (i = 0; i < len; i++) { @@ -1241,7 +1273,8 @@ static int read_mem(struct scsi_cmnd *srb, struct rtsx_chip *chip) vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } @@ -1274,13 +1307,16 @@ static int write_mem(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (addr < 0xFC00) { set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } len = (unsigned short)min_t(unsigned int, scsi_bufflen(srb), len); buf = vmalloc(len); - if (buf == NULL) - TRACE_RET(chip, TRANSPORT_ERROR); + if (buf == NULL) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } rtsx_stor_get_xfer_buf(buf, len, srb); scsi_set_resid(srb, scsi_bufflen(srb) - len); @@ -1289,7 +1325,8 @@ static int write_mem(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (retval != STATUS_SUCCESS) { vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } for (i = 0; i < len; i++) { @@ -1298,7 +1335,8 @@ static int write_mem(struct scsi_cmnd *srb, struct rtsx_chip *chip) vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } @@ -1314,12 +1352,14 @@ static int get_sd_csd(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!check_card_ready(chip, lun)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (get_lun_card(chip, lun) != SD_CARD) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } scsi_set_resid(srb, 0); @@ -1361,14 +1401,17 @@ static int trace_msg_cmd(struct scsi_cmnd *srb, struct rtsx_chip *chip) if ((scsi_bufflen(srb) < buf_len) || (scsi_sglist(srb) == NULL)) { set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } clear = srb->cmnd[2]; buf = vmalloc(scsi_bufflen(srb)); - if (buf == NULL) - TRACE_RET(chip, TRANSPORT_ERROR); + if (buf == NULL) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } ptr = buf; if (chip->trace_msg[chip->msg_idx].valid) @@ -1500,7 +1543,8 @@ static int set_variable(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; } } else if (srb->cmnd[3] == 2) { if (srb->cmnd[4]) { @@ -1523,14 +1567,16 @@ static int set_variable(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (retval != STATUS_SUCCESS) { set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } turn_off_led(chip, LED_GPIO); } } else { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } return TRANSPORT_GOOD; @@ -1562,7 +1608,8 @@ static int get_variable(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; } rtsx_stor_set_xfer_buf(&tmp, 1, srb); @@ -1572,7 +1619,8 @@ static int get_variable(struct scsi_cmnd *srb, struct rtsx_chip *chip) rtsx_stor_set_xfer_buf(&tmp, 1, srb); } else { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } return TRANSPORT_GOOD; @@ -1610,7 +1658,8 @@ static int dma_access_ring_buffer(struct scsi_cmnd *srb, struct rtsx_chip *chip) set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } scsi_set_resid(srb, 0); @@ -1757,7 +1806,8 @@ static int set_chip_mode(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!CHECK_PID(chip, 0x5208)) { set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } phy_debug_mode = (int)(srb->cmnd[3]); @@ -1765,35 +1815,47 @@ static int set_chip_mode(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (phy_debug_mode) { chip->phy_debug_mode = 1; retval = rtsx_write_register(chip, CDRESUMECTL, 0x77, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } rtsx_disable_bus_int(chip); retval = rtsx_read_phy_register(chip, 0x1C, ®); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } reg |= 0x0001; retval = rtsx_write_phy_register(chip, 0x1C, reg); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } } else { chip->phy_debug_mode = 0; retval = rtsx_write_register(chip, CDRESUMECTL, 0x77, 0x77); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } rtsx_enable_bus_int(chip); retval = rtsx_read_phy_register(chip, 0x1C, ®); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } reg &= 0xFFFE; retval = rtsx_write_phy_register(chip, 0x1C, reg); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } } return TRANSPORT_GOOD; @@ -1824,7 +1886,8 @@ static int rw_mem_cmd_buf(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (cmd_type > 2) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } addr = (srb->cmnd[5] << 8) | srb->cmnd[6]; mask = srb->cmnd[7]; @@ -1842,7 +1905,8 @@ static int rw_mem_cmd_buf(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (scsi_bufflen(srb) < 1) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } rtsx_stor_set_xfer_buf(&value, 1, srb); scsi_set_resid(srb, 0); @@ -1850,12 +1914,14 @@ static int rw_mem_cmd_buf(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; } if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } return TRANSPORT_GOOD; @@ -1902,15 +1968,18 @@ static int read_phy_register(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (len) { buf = vmalloc(len); - if (!buf) - TRACE_RET(chip, TRANSPORT_ERROR); + if (!buf) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } retval = rtsx_force_power_on(chip, SSC_PDCTL); if (retval != STATUS_SUCCESS) { vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } for (i = 0; i < len / 2; i++) { @@ -1919,7 +1988,8 @@ static int read_phy_register(struct scsi_cmnd *srb, struct rtsx_chip *chip) vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } buf[2*i] = (u8)(val >> 8); @@ -1963,8 +2033,10 @@ static int write_phy_register(struct scsi_cmnd *srb, struct rtsx_chip *chip) len); buf = vmalloc(len); - if (buf == NULL) - TRACE_RET(chip, TRANSPORT_ERROR); + if (buf == NULL) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } rtsx_stor_get_xfer_buf(buf, len, srb); scsi_set_resid(srb, scsi_bufflen(srb) - len); @@ -1974,7 +2046,8 @@ static int write_phy_register(struct scsi_cmnd *srb, struct rtsx_chip *chip) vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } for (i = 0; i < len / 2; i++) { @@ -1984,7 +2057,8 @@ static int write_phy_register(struct scsi_cmnd *srb, struct rtsx_chip *chip) vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } @@ -2011,7 +2085,8 @@ static int erase_eeprom2(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = rtsx_force_power_on(chip, SSC_PDCTL); if (retval != STATUS_SUCCESS) { set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } mode = srb->cmnd[3]; @@ -2022,19 +2097,22 @@ static int erase_eeprom2(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (retval != STATUS_SUCCESS) { set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } else if (mode == 1) { retval = spi_erase_eeprom_byte(chip, addr); if (retval != STATUS_SUCCESS) { set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } else { set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } return TRANSPORT_GOOD; @@ -2058,15 +2136,18 @@ static int read_eeprom2(struct scsi_cmnd *srb, struct rtsx_chip *chip) len = ((u16)srb->cmnd[6] << 8) | srb->cmnd[7]; buf = vmalloc(len); - if (!buf) - TRACE_RET(chip, TRANSPORT_ERROR); + if (!buf) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } retval = rtsx_force_power_on(chip, SSC_PDCTL); if (retval != STATUS_SUCCESS) { vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } for (i = 0; i < len; i++) { @@ -2075,7 +2156,8 @@ static int read_eeprom2(struct scsi_cmnd *srb, struct rtsx_chip *chip) vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } @@ -2107,8 +2189,10 @@ static int write_eeprom2(struct scsi_cmnd *srb, struct rtsx_chip *chip) len = (unsigned short)min_t(unsigned int, scsi_bufflen(srb), len); buf = vmalloc(len); - if (buf == NULL) - TRACE_RET(chip, TRANSPORT_ERROR); + if (buf == NULL) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } rtsx_stor_get_xfer_buf(buf, len, srb); scsi_set_resid(srb, scsi_bufflen(srb) - len); @@ -2117,7 +2201,8 @@ static int write_eeprom2(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (retval != STATUS_SUCCESS) { vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } for (i = 0; i < len; i++) { @@ -2126,7 +2211,8 @@ static int write_eeprom2(struct scsi_cmnd *srb, struct rtsx_chip *chip) vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } @@ -2153,15 +2239,18 @@ static int read_efuse(struct scsi_cmnd *srb, struct rtsx_chip *chip) len = srb->cmnd[5]; buf = vmalloc(len); - if (!buf) - TRACE_RET(chip, TRANSPORT_ERROR); + if (!buf) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } retval = rtsx_force_power_on(chip, SSC_PDCTL); if (retval != STATUS_SUCCESS) { vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } for (i = 0; i < len; i++) { @@ -2170,7 +2259,8 @@ static int read_efuse(struct scsi_cmnd *srb, struct rtsx_chip *chip) vfree(buf); set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } @@ -2203,8 +2293,10 @@ static int write_efuse(struct scsi_cmnd *srb, struct rtsx_chip *chip) len = (u8)min_t(unsigned int, scsi_bufflen(srb), len); buf = vmalloc(len); - if (buf == NULL) - TRACE_RET(chip, TRANSPORT_ERROR); + if (buf == NULL) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } rtsx_stor_get_xfer_buf(buf, len, srb); scsi_set_resid(srb, scsi_bufflen(srb) - len); @@ -2212,21 +2304,24 @@ static int write_efuse(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = rtsx_force_power_on(chip, SSC_PDCTL); if (retval != STATUS_SUCCESS) { vfree(buf); - TRACE_RET(chip, TRANSPORT_ERROR); + rtsx_trace(chip); + return TRANSPORT_ERROR; } if (chip->asic_code) { retval = rtsx_read_phy_register(chip, 0x08, &val); if (retval != STATUS_SUCCESS) { vfree(buf); - TRACE_RET(chip, TRANSPORT_ERROR); + rtsx_trace(chip); + return TRANSPORT_ERROR; } retval = rtsx_write_register(chip, PWR_GATE_CTRL, LDO3318_PWR_MASK, LDO_OFF); if (retval != STATUS_SUCCESS) { vfree(buf); - TRACE_RET(chip, TRANSPORT_ERROR); + rtsx_trace(chip); + return TRANSPORT_ERROR; } wait_timeout(600); @@ -2235,14 +2330,16 @@ static int write_efuse(struct scsi_cmnd *srb, struct rtsx_chip *chip) 0x4C00 | chip->phy_voltage); if (retval != STATUS_SUCCESS) { vfree(buf); - TRACE_RET(chip, TRANSPORT_ERROR); + rtsx_trace(chip); + return TRANSPORT_ERROR; } retval = rtsx_write_register(chip, PWR_GATE_CTRL, LDO3318_PWR_MASK, LDO_ON); if (retval != STATUS_SUCCESS) { vfree(buf); - TRACE_RET(chip, TRANSPORT_ERROR); + rtsx_trace(chip); + return TRANSPORT_ERROR; } wait_timeout(600); @@ -2251,7 +2348,8 @@ static int write_efuse(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = card_power_on(chip, SPI_CARD); if (retval != STATUS_SUCCESS) { vfree(buf); - TRACE_RET(chip, TRANSPORT_ERROR); + rtsx_trace(chip); + return TRANSPORT_ERROR; } wait_timeout(50); @@ -2262,7 +2360,8 @@ static int write_efuse(struct scsi_cmnd *srb, struct rtsx_chip *chip) set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR); result = TRANSPORT_FAILED; - TRACE_GOTO(chip, Exit); + rtsx_trace(chip); + goto Exit; } } @@ -2270,25 +2369,33 @@ Exit: vfree(buf); retval = card_power_off(chip, SPI_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_ERROR); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } if (chip->asic_code) { retval = rtsx_write_register(chip, PWR_GATE_CTRL, LDO3318_PWR_MASK, LDO_OFF); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_ERROR); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } wait_timeout(600); retval = rtsx_write_phy_register(chip, 0x08, val); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_ERROR); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } retval = rtsx_write_register(chip, PWR_GATE_CTRL, LDO3318_PWR_MASK, LDO_ON); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_ERROR); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } } return result; @@ -2325,19 +2432,23 @@ static int read_cfg_byte(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (func > func_max) { set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } buf = vmalloc(len); - if (!buf) - TRACE_RET(chip, TRANSPORT_ERROR); + if (!buf) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } retval = rtsx_read_cfg_seq(chip, func, addr, buf, len); if (retval != STATUS_SUCCESS) { set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); vfree(buf); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } len = (u16)min_t(unsigned int, scsi_bufflen(srb), len); @@ -2380,13 +2491,16 @@ static int write_cfg_byte(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (func > func_max) { set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } len = (unsigned short)min_t(unsigned int, scsi_bufflen(srb), len); buf = vmalloc(len); - if (!buf) - TRACE_RET(chip, TRANSPORT_ERROR); + if (!buf) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } rtsx_stor_get_xfer_buf(buf, len, srb); scsi_set_resid(srb, scsi_bufflen(srb) - len); @@ -2395,7 +2509,8 @@ static int write_cfg_byte(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (retval != STATUS_SUCCESS) { set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_WRITE_ERR); vfree(buf); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } vfree(buf); @@ -2485,7 +2600,8 @@ static int app_cmd(struct scsi_cmnd *srb, struct rtsx_chip *chip) default: set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } return result; @@ -2628,7 +2744,8 @@ static int get_card_bus_width(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!check_card_ready(chip, lun)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } card = get_lun_card(chip, lun); @@ -2636,7 +2753,8 @@ static int get_card_bus_width(struct scsi_cmnd *srb, struct rtsx_chip *chip) bus_width = chip->card_bus_width[lun]; } else { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } scsi_set_resid(srb, 0); @@ -2653,7 +2771,8 @@ static int spi_vendor_cmd(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (CHECK_PID(chip, 0x5208) || CHECK_PID(chip, 0x5288)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } rtsx_disable_aspm(chip); @@ -2702,13 +2821,16 @@ static int spi_vendor_cmd(struct scsi_cmnd *srb, struct rtsx_chip *chip) rtsx_write_register(chip, CARD_GPIO_DIR, 0x07, gpio_dir); set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } rtsx_write_register(chip, CARD_GPIO_DIR, 0x07, gpio_dir); - if (result != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (result != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } return TRANSPORT_GOOD; } @@ -2767,7 +2889,8 @@ static int vendor_cmnd(struct scsi_cmnd *srb, struct rtsx_chip *chip) default: set_sense_type(chip, SCSI_LUN(srb), SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } return result; @@ -2804,14 +2927,16 @@ static int ms_format_cmnd(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (get_lun_card(chip, lun) != MS_CARD) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if ((srb->cmnd[3] != 0x4D) || (srb->cmnd[4] != 0x47) || (srb->cmnd[5] != 0x66) || (srb->cmnd[6] != 0x6D) || (srb->cmnd[7] != 0x74)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } rtsx_disable_aspm(chip); @@ -2823,7 +2948,8 @@ static int ms_format_cmnd(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!check_card_ready(chip, lun) || (get_card_size(chip, lun) == 0)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } rtsx_set_stat(chip, RTSX_STAT_RUN); @@ -2835,23 +2961,27 @@ static int ms_format_cmnd(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!(chip->card_ready & MS_CARD)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (chip->card_wp & MS_CARD) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_PROTECT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (!CHK_MSPRO(ms_card)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } retval = mspro_format(srb, chip, MS_SHORT_DATA_LEN, quick_format); if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_FORMAT_CMD_FAILED); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } scsi_set_resid(srb, 0); @@ -2870,18 +3000,21 @@ static int get_ms_information(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!check_card_ready(chip, lun)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (get_lun_card(chip, lun) != MS_CARD) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if ((srb->cmnd[2] != 0xB0) || (srb->cmnd[4] != 0x4D) || (srb->cmnd[5] != 0x53) || (srb->cmnd[6] != 0x49) || (srb->cmnd[7] != 0x44)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } dev_info_id = srb->cmnd[3]; @@ -2889,7 +3022,8 @@ static int get_ms_information(struct scsi_cmnd *srb, struct rtsx_chip *chip) (!CHK_MSXC(ms_card) && (dev_info_id == 0x13)) || !CHK_MSPRO(ms_card)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (dev_info_id == 0x15) @@ -2898,8 +3032,10 @@ static int get_ms_information(struct scsi_cmnd *srb, struct rtsx_chip *chip) buf_len = data_len = 0x6A; buf = kmalloc(buf_len, GFP_KERNEL); - if (!buf) - TRACE_RET(chip, TRANSPORT_ERROR); + if (!buf) { + rtsx_trace(chip); + return TRANSPORT_ERROR; + } i = 0; /* GET Memory Stick Media Information Response Header */ @@ -2986,11 +3122,13 @@ static int sd_extention_cmnd(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!check_card_ready(chip, lun)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (get_lun_card(chip, lun) != SD_CARD) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } switch (srb->cmnd[0]) { @@ -3020,7 +3158,8 @@ static int sd_extention_cmnd(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; } return result; @@ -3047,21 +3186,25 @@ static int mg_report_key(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!check_card_ready(chip, lun)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (get_lun_card(chip, lun) != MS_CARD) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (srb->cmnd[7] != KC_MG_R_PRO) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (!CHK_MSPRO(ms_card)) { set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } key_format = srb->cmnd[10] & 0x3F; @@ -3073,13 +3216,16 @@ static int mg_report_key(struct scsi_cmnd *srb, struct rtsx_chip *chip) (srb->cmnd[8] == 0x04) && (srb->cmnd[9] == 0x1C)) { retval = mg_get_local_EKB(srb, chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } } else { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } break; @@ -3088,13 +3234,16 @@ static int mg_report_key(struct scsi_cmnd *srb, struct rtsx_chip *chip) (srb->cmnd[8] == 0x00) && (srb->cmnd[9] == 0x24)) { retval = mg_get_rsp_chg(srb, chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } } else { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } break; @@ -3108,19 +3257,23 @@ static int mg_report_key(struct scsi_cmnd *srb, struct rtsx_chip *chip) (srb->cmnd[4] == 0x00) && (srb->cmnd[5] < 32)) { retval = mg_get_ICV(srb, chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } } else { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - 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); @@ -3146,25 +3299,30 @@ static int mg_send_key(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (!check_card_ready(chip, lun)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (check_card_wp(chip, lun)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_PROTECT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (get_lun_card(chip, lun) != MS_CARD) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (srb->cmnd[7] != KC_MG_R_PRO) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } if (!CHK_MSPRO(ms_card)) { set_sense_type(chip, lun, SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } key_format = srb->cmnd[10] & 0x3F; @@ -3176,13 +3334,16 @@ static int mg_send_key(struct scsi_cmnd *srb, struct rtsx_chip *chip) (srb->cmnd[8] == 0x00) && (srb->cmnd[9] == 0x0C)) { retval = mg_set_leaf_id(srb, chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } } else { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } break; @@ -3191,13 +3352,16 @@ static int mg_send_key(struct scsi_cmnd *srb, struct rtsx_chip *chip) (srb->cmnd[8] == 0x00) && (srb->cmnd[9] == 0x0C)) { retval = mg_chg(srb, chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } } else { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } break; @@ -3206,13 +3370,16 @@ static int mg_send_key(struct scsi_cmnd *srb, struct rtsx_chip *chip) (srb->cmnd[8] == 0x00) && (srb->cmnd[9] == 0x0C)) { retval = mg_rsp(srb, chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } } else { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } break; @@ -3226,19 +3393,23 @@ static int mg_send_key(struct scsi_cmnd *srb, struct rtsx_chip *chip) (srb->cmnd[4] == 0x00) && (srb->cmnd[5] < 32)) { retval = mg_set_ICV(srb, chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, TRANSPORT_FAILED); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return TRANSPORT_FAILED; + } } else { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_INVALID_CMD_FIELD); - 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); @@ -3267,7 +3438,8 @@ int rtsx_scsi_handler(struct scsi_cmnd *srb, struct rtsx_chip *chip) /* Logical Unit Not Ready Format in Progress */ set_sense_data(chip, lun, CUR_ERR, 0x02, 0, 0x04, 0x04, 0, 0); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } #endif @@ -3279,7 +3451,8 @@ int rtsx_scsi_handler(struct scsi_cmnd *srb, struct rtsx_chip *chip) /* Logical Unit Not Ready Format in Progress */ set_sense_data(chip, lun, CUR_ERR, 0x02, 0, 0x04, 0x04, 0, (u16)(ms_card->progress)); - TRACE_RET(chip, TRANSPORT_FAILED); + rtsx_trace(chip); + return TRANSPORT_FAILED; } } diff --git a/drivers/staging/rts5208/rtsx_transport.c b/drivers/staging/rts5208/rtsx_transport.c index 03caa9b3771f..f27491e802ed 100644 --- a/drivers/staging/rts5208/rtsx_transport.c +++ b/drivers/staging/rts5208/rtsx_transport.c @@ -25,10 +25,6 @@ #include #include "rtsx.h" -#include "rtsx_scsi.h" -#include "rtsx_transport.h" -#include "rtsx_chip.h" -#include "rtsx_card.h" /*********************************************************************** * Scatter-gather transfer buffer access routines @@ -276,7 +272,8 @@ int rtsx_send_cmd(struct rtsx_chip *chip, u8 card, int timeout) dev_dbg(rtsx_dev(chip), "chip->int_reg = 0x%x\n", chip->int_reg); err = -ETIMEDOUT; - TRACE_GOTO(chip, finish_send_cmd); + rtsx_trace(chip); + goto finish_send_cmd; } spin_lock_irq(&rtsx->reg_lock); diff --git a/drivers/staging/rts5208/sd.c b/drivers/staging/rts5208/sd.c index a03cbe93722a..0eee67642e45 100644 --- a/drivers/staging/rts5208/sd.c +++ b/drivers/staging/rts5208/sd.c @@ -25,9 +25,6 @@ #include #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; } diff --git a/drivers/staging/rts5208/spi.c b/drivers/staging/rts5208/spi.c index 29f4a80844fa..d3ac6c0b11b5 100644 --- a/drivers/staging/rts5208/spi.c +++ b/drivers/staging/rts5208/spi.c @@ -25,9 +25,6 @@ #include #include "rtsx.h" -#include "rtsx_transport.h" -#include "rtsx_scsi.h" -#include "rtsx_card.h" #include "spi.h" static inline void spi_set_err_code(struct rtsx_chip *chip, u8 err_code) @@ -56,12 +53,16 @@ static int spi_set_init_para(struct rtsx_chip *chip) RTSX_WRITE_REG(chip, SPI_CLK_DIVIDER0, 0xFF, (u8)(spi->clk_div)); retval = switch_clock(chip, spi->spi_clock); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = select_card(chip, SPI_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_CLK_EN, SPI_CLK_EN, SPI_CLK_EN); RTSX_WRITE_REG(chip, CARD_OE, SPI_OUTPUT_EN, SPI_OUTPUT_EN); @@ -69,8 +70,10 @@ static int spi_set_init_para(struct rtsx_chip *chip) wait_timeout(10); retval = spi_init(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -91,7 +94,8 @@ static int sf_polling_status(struct rtsx_chip *chip, int msec) if (retval < 0) { rtsx_clear_spi_error(chip); spi_set_err_code(chip, SPI_BUSY_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -119,7 +123,8 @@ static int sf_enable_write(struct rtsx_chip *chip, u8 ins) if (retval < 0) { rtsx_clear_spi_error(chip); spi_set_err_code(chip, SPI_HW_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -147,7 +152,8 @@ static int sf_disable_write(struct rtsx_chip *chip, u8 ins) if (retval < 0) { rtsx_clear_spi_error(chip); spi_set_err_code(chip, SPI_HW_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -205,7 +211,8 @@ static int sf_erase(struct rtsx_chip *chip, u8 ins, u8 addr_mode, u32 addr) if (retval < 0) { rtsx_clear_spi_error(chip); spi_set_err_code(chip, SPI_HW_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -225,12 +232,16 @@ static int spi_init_eeprom(struct rtsx_chip *chip) RTSX_WRITE_REG(chip, SPI_CLK_DIVIDER0, 0xFF, 0x27); retval = switch_clock(chip, clk); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = select_card(chip, SPI_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_CLK_EN, SPI_CLK_EN, SPI_CLK_EN); RTSX_WRITE_REG(chip, CARD_OE, SPI_OUTPUT_EN, SPI_OUTPUT_EN); @@ -258,8 +269,10 @@ static int spi_eeprom_program_enable(struct rtsx_chip *chip) SPI_TRANSFER0_END); retval = rtsx_send_cmd(chip, 0, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -269,12 +282,16 @@ int spi_erase_eeprom_chip(struct rtsx_chip *chip) int retval; retval = spi_init_eeprom(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = spi_eeprom_program_enable(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -288,8 +305,10 @@ int spi_erase_eeprom_chip(struct rtsx_chip *chip) SPI_TRANSFER0_END); retval = rtsx_send_cmd(chip, 0, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_WRITE_REG(chip, CARD_GPIO_DIR, 0x01, 0x01); @@ -301,12 +320,16 @@ int spi_erase_eeprom_byte(struct rtsx_chip *chip, u16 addr) int retval; retval = spi_init_eeprom(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = spi_eeprom_program_enable(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -322,8 +345,10 @@ int spi_erase_eeprom_byte(struct rtsx_chip *chip, u16 addr) SPI_TRANSFER0_END); retval = rtsx_send_cmd(chip, 0, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_WRITE_REG(chip, CARD_GPIO_DIR, 0x01, 0x01); @@ -337,8 +362,10 @@ int spi_read_eeprom(struct rtsx_chip *chip, u16 addr, u8 *val) u8 data; retval = spi_init_eeprom(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -355,8 +382,10 @@ int spi_read_eeprom(struct rtsx_chip *chip, u16 addr, u8 *val) SPI_TRANSFER0_END); retval = rtsx_send_cmd(chip, 0, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } wait_timeout(5); RTSX_READ_REG(chip, SPI_DATA, &data); @@ -374,12 +403,16 @@ int spi_write_eeprom(struct rtsx_chip *chip, u16 addr, u8 val) int retval; retval = spi_init_eeprom(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = spi_eeprom_program_enable(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -396,8 +429,10 @@ int spi_write_eeprom(struct rtsx_chip *chip, u16 addr, u8 val) SPI_TRANSFER0_END); retval = rtsx_send_cmd(chip, 0, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } RTSX_WRITE_REG(chip, CARD_GPIO_DIR, 0x01, 0x01); @@ -449,13 +484,15 @@ int spi_read_flash_id(struct scsi_cmnd *srb, struct rtsx_chip *chip) len = ((u16)(srb->cmnd[7]) << 8) | srb->cmnd[8]; if (len > 512) { spi_set_err_code(chip, SPI_INVALID_COMMAND); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = spi_set_init_para(chip); if (retval != STATUS_SUCCESS) { spi_set_err_code(chip, SPI_HW_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } rtsx_init_cmd(chip); @@ -497,19 +534,23 @@ int spi_read_flash_id(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (retval < 0) { rtsx_clear_spi_error(chip); spi_set_err_code(chip, SPI_HW_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (len) { buf = kmalloc(len, GFP_KERNEL); - if (!buf) - TRACE_RET(chip, STATUS_ERROR); + if (!buf) { + rtsx_trace(chip); + return STATUS_ERROR; + } retval = rtsx_read_ppbuf(chip, buf, len); if (retval != STATUS_SUCCESS) { spi_set_err_code(chip, SPI_READ_ERR); kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } rtsx_stor_set_xfer_buf(buf, scsi_bufflen(srb), srb); @@ -541,12 +582,15 @@ int spi_read_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = spi_set_init_para(chip); if (retval != STATUS_SUCCESS) { spi_set_err_code(chip, SPI_HW_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } buf = kmalloc(SF_PAGE_LEN, GFP_KERNEL); - if (buf == NULL) - TRACE_RET(chip, STATUS_ERROR); + if (buf == NULL) { + rtsx_trace(chip); + return STATUS_ERROR; + } while (len) { u16 pagelen = SF_PAGE_LEN - (u8)addr; @@ -598,7 +642,8 @@ int spi_read_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) kfree(buf); rtsx_clear_spi_error(chip); spi_set_err_code(chip, SPI_HW_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } rtsx_stor_access_xfer_buf(buf, pagelen, srb, &index, &offset, @@ -634,19 +679,23 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = spi_set_init_para(chip); if (retval != STATUS_SUCCESS) { spi_set_err_code(chip, SPI_HW_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (program_mode == BYTE_PROGRAM) { buf = kmalloc(4, GFP_KERNEL); - if (!buf) - TRACE_RET(chip, STATUS_ERROR); + if (!buf) { + rtsx_trace(chip); + return STATUS_ERROR; + } while (len) { retval = sf_enable_write(chip, SPI_WREN); if (retval != STATUS_SUCCESS) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } rtsx_stor_access_xfer_buf(buf, 1, srb, &index, &offset, @@ -665,13 +714,15 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) kfree(buf); rtsx_clear_spi_error(chip); spi_set_err_code(chip, SPI_HW_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = sf_polling_status(chip, 100); if (retval != STATUS_SUCCESS) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } addr++; @@ -684,12 +735,16 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) int first_byte = 1; retval = sf_enable_write(chip, SPI_WREN); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } buf = kmalloc(4, GFP_KERNEL); - if (!buf) - TRACE_RET(chip, STATUS_ERROR); + if (!buf) { + rtsx_trace(chip); + return STATUS_ERROR; + } while (len) { rtsx_stor_access_xfer_buf(buf, 1, srb, &index, &offset, @@ -713,13 +768,15 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) kfree(buf); rtsx_clear_spi_error(chip); spi_set_err_code(chip, SPI_HW_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = sf_polling_status(chip, 100); if (retval != STATUS_SUCCESS) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } len--; @@ -728,16 +785,22 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) kfree(buf); retval = sf_disable_write(chip, SPI_WRDI); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sf_polling_status(chip, 100); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else if (program_mode == PAGE_PROGRAM) { buf = kmalloc(SF_PAGE_LEN, GFP_KERNEL); - if (!buf) - TRACE_RET(chip, STATUS_NOMEM); + if (!buf) { + rtsx_trace(chip); + return STATUS_NOMEM; + } while (len) { u16 pagelen = SF_PAGE_LEN - (u8)addr; @@ -748,7 +811,8 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = sf_enable_write(chip, SPI_WREN); if (retval != STATUS_SUCCESS) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } rtsx_init_cmd(chip); @@ -767,13 +831,15 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) kfree(buf); rtsx_clear_spi_error(chip); spi_set_err_code(chip, SPI_HW_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = sf_polling_status(chip, 100); if (retval != STATUS_SUCCESS) { kfree(buf); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } addr += pagelen; @@ -783,7 +849,8 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) kfree(buf); } else { spi_set_err_code(chip, SPI_INVALID_COMMAND); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -805,28 +872,38 @@ int spi_erase_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = spi_set_init_para(chip); if (retval != STATUS_SUCCESS) { spi_set_err_code(chip, SPI_HW_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (erase_mode == PAGE_ERASE) { retval = sf_enable_write(chip, SPI_WREN); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sf_erase(chip, ins, 1, addr); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else if (erase_mode == CHIP_ERASE) { retval = sf_enable_write(chip, SPI_WREN); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = sf_erase(chip, ins, 0, 0); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } else { spi_set_err_code(chip, SPI_INVALID_COMMAND); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -844,12 +921,15 @@ int spi_write_flash_status(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = spi_set_init_para(chip); if (retval != STATUS_SUCCESS) { spi_set_err_code(chip, SPI_HW_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = sf_enable_write(chip, ewsr); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -871,7 +951,8 @@ int spi_write_flash_status(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (retval != STATUS_SUCCESS) { rtsx_clear_spi_error(chip); spi_set_err_code(chip, SPI_HW_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; diff --git a/drivers/staging/rts5208/trace.c b/drivers/staging/rts5208/trace.c new file mode 100644 index 000000000000..1bddbdf3454b --- /dev/null +++ b/drivers/staging/rts5208/trace.c @@ -0,0 +1,26 @@ +#include +#include + +#include "rtsx.h" + +#ifdef _MSG_TRACE + +void _rtsx_trace(struct rtsx_chip *chip, const char *file, const char *func, + int line) +{ + struct trace_msg_t *msg = &chip->trace_msg[chip->msg_idx]; + + file = kbasename(file); + dev_dbg(rtsx_dev(chip), "[%s][%s]:[%d]\n", file, func, line); + + strncpy(msg->file, file, MSG_FILE_LEN - 1); + strncpy(msg->func, func, MSG_FUNC_LEN - 1); + msg->line = (u16)line; + get_current_time(msg->timeval_buf, TIME_VAL_LEN); + msg->valid = 1; + + chip->msg_idx++; + if (chip->msg_idx >= TRACE_ITEM_CNT) + chip->msg_idx = 0; +} +#endif diff --git a/drivers/staging/rts5208/trace.h b/drivers/staging/rts5208/trace.h index a9ab4077b283..5b807874c1d7 100644 --- a/drivers/staging/rts5208/trace.h +++ b/drivers/staging/rts5208/trace.h @@ -24,64 +24,17 @@ #ifndef __REALTEK_RTSX_TRACE_H #define __REALTEK_RTSX_TRACE_H -#define _MSG_TRACE +struct rtsx_chip; #ifdef _MSG_TRACE -static inline char *filename(char *path) +void _rtsx_trace(struct rtsx_chip *chip, const char *file, const char *func, + int line); +#define rtsx_trace(chip) \ + _rtsx_trace(chip, __FILE__, __func__, __LINE__) +#else +static inline void rtsx_trace(struct rtsx_chip *chip) { - char *ptr; - - if (path == NULL) - return NULL; - - ptr = path; - - while (*ptr != '\0') { - if ((*ptr == '\\') || (*ptr == '/')) - path = ptr + 1; - - ptr++; - } - - return path; } - -#define TRACE_RET(chip, ret) \ - do { \ - char *_file = filename(__FILE__); \ - dev_dbg(rtsx_dev(chip), "[%s][%s]:[%d]\n", _file, \ - __func__, __LINE__); \ - (chip)->trace_msg[(chip)->msg_idx].line = (u16)(__LINE__); \ - strncpy((chip)->trace_msg[(chip)->msg_idx].func, __func__, MSG_FUNC_LEN-1); \ - strncpy((chip)->trace_msg[(chip)->msg_idx].file, _file, MSG_FILE_LEN-1); \ - get_current_time((chip)->trace_msg[(chip)->msg_idx].timeval_buf, TIME_VAL_LEN); \ - (chip)->trace_msg[(chip)->msg_idx].valid = 1; \ - (chip)->msg_idx++; \ - if ((chip)->msg_idx >= TRACE_ITEM_CNT) { \ - (chip)->msg_idx = 0; \ - } \ - return ret; \ - } while (0) - -#define TRACE_GOTO(chip, label) \ - do { \ - char *_file = filename(__FILE__); \ - dev_dbg(rtsx_dev(chip), "[%s][%s]:[%d]\n", _file, \ - __func__, __LINE__); \ - (chip)->trace_msg[(chip)->msg_idx].line = (u16)(__LINE__); \ - strncpy((chip)->trace_msg[(chip)->msg_idx].func, __func__, MSG_FUNC_LEN-1); \ - strncpy((chip)->trace_msg[(chip)->msg_idx].file, _file, MSG_FILE_LEN-1); \ - get_current_time((chip)->trace_msg[(chip)->msg_idx].timeval_buf, TIME_VAL_LEN); \ - (chip)->trace_msg[(chip)->msg_idx].valid = 1; \ - (chip)->msg_idx++; \ - if ((chip)->msg_idx >= TRACE_ITEM_CNT) { \ - (chip)->msg_idx = 0; \ - } \ - goto label; \ - } while (0) -#else -#define TRACE_RET(chip, ret) return ret -#define TRACE_GOTO(chip, label) goto label #endif #endif /* __REALTEK_RTSX_TRACE_H */ diff --git a/drivers/staging/rts5208/xd.c b/drivers/staging/rts5208/xd.c index 0d029fe92b40..2afa6021c33b 100644 --- a/drivers/staging/rts5208/xd.c +++ b/drivers/staging/rts5208/xd.c @@ -60,8 +60,10 @@ static int xd_set_init_para(struct rtsx_chip *chip) xd_card->xd_clock = CLK_50; retval = switch_clock(chip, xd_card->xd_clock); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -72,12 +74,16 @@ static int xd_switch_clock(struct rtsx_chip *chip) int retval; retval = select_card(chip, XD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = switch_clock(chip, xd_card->xd_clock); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -99,8 +105,10 @@ static int xd_read_id(struct rtsx_chip *chip, u8 id_cmd, u8 *id_buf, u8 buf_len) rtsx_add_cmd(chip, READ_REG_CMD, (u16)(XD_ADDRESS1 + i), 0, 0); retval = rtsx_send_cmd(chip, XD_CARD, 20); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } ptr = rtsx_get_cmd_data(chip) + 1; if (id_buf && buf_len) { @@ -167,8 +175,10 @@ static int xd_read_redundant(struct rtsx_chip *chip, u32 page_addr, rtsx_add_cmd(chip, READ_REG_CMD, XD_PARITY, 0, 0); retval = rtsx_send_cmd(chip, XD_CARD, 500); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (buf && buf_len) { u8 *ptr = rtsx_get_cmd_data(chip) + 1; @@ -186,8 +196,10 @@ static int xd_read_data_from_ppb(struct rtsx_chip *chip, int offset, { int retval, i; - if (!buf || (buf_len < 0)) - TRACE_RET(chip, STATUS_FAIL); + if (!buf || (buf_len < 0)) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -198,7 +210,8 @@ static int xd_read_data_from_ppb(struct rtsx_chip *chip, int offset, retval = rtsx_send_cmd(chip, 0, 250); if (retval < 0) { rtsx_clear_xd_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } memcpy(buf, rtsx_get_cmd_data(chip), buf_len); @@ -212,8 +225,10 @@ static int xd_read_cis(struct rtsx_chip *chip, u32 page_addr, u8 *buf, int retval; u8 reg; - if (!buf || (buf_len < 10)) - TRACE_RET(chip, STATUS_FAIL); + if (!buf || (buf_len < 10)) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -233,20 +248,24 @@ static int xd_read_cis(struct rtsx_chip *chip, u32 page_addr, u8 *buf, retval = rtsx_send_cmd(chip, XD_CARD, 250); if (retval == -ETIMEDOUT) { rtsx_clear_xd_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } RTSX_READ_REG(chip, XD_PAGE_STATUS, ®); if (reg != XD_GPG) { rtsx_clear_xd_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } RTSX_READ_REG(chip, XD_CTL, ®); if (!(reg & XD_ECC1_ERROR) || !(reg & XD_ECC1_UNCORRECTABLE)) { retval = xd_read_data_from_ppb(chip, 0, buf, buf_len); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (reg & XD_ECC1_ERROR) { u8 ecc_bit, ecc_byte; @@ -267,8 +286,10 @@ static int xd_read_cis(struct rtsx_chip *chip, u32 page_addr, u8 *buf, rtsx_clear_xd_error(chip); retval = xd_read_data_from_ppb(chip, 256, buf, buf_len); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (reg & XD_ECC2_ERROR) { u8 ecc_bit, ecc_byte; @@ -287,7 +308,8 @@ static int xd_read_cis(struct rtsx_chip *chip, u32 page_addr, u8 *buf, } } else { rtsx_clear_xd_error(chip); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -394,8 +416,10 @@ static int reset_xd(struct rtsx_chip *chip) u8 *ptr, id_buf[4], redunt[11]; retval = select_card(chip, XD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -418,13 +442,17 @@ static int reset_xd(struct rtsx_chip *chip) rtsx_add_cmd(chip, WRITE_REG_CMD, CARD_OE, XD_OUTPUT_EN, 0); retval = rtsx_send_cmd(chip, XD_CARD, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (!chip->ft2_fast_mode) { retval = card_power_off(chip, XD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } wait_timeout(250); @@ -439,19 +467,24 @@ static int reset_xd(struct rtsx_chip *chip) } retval = rtsx_send_cmd(chip, XD_CARD, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = card_power_on(chip, XD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } #ifdef SUPPORT_OCP wait_timeout(50); 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 } @@ -472,15 +505,19 @@ static int reset_xd(struct rtsx_chip *chip) rtsx_add_cmd(chip, WRITE_REG_CMD, XD_CTL, XD_CE_DISEN, XD_CE_DISEN); retval = rtsx_send_cmd(chip, XD_CARD, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (!chip->ft2_fast_mode) wait_timeout(200); retval = xd_set_init_para(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } /* Read ID to check if the timing setting is right */ for (i = 0; i < 4; i++) { @@ -502,8 +539,10 @@ static int reset_xd(struct rtsx_chip *chip) rtsx_add_cmd(chip, READ_REG_CMD, XD_CTL, 0, 0); retval = rtsx_send_cmd(chip, XD_CARD, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } ptr = rtsx_get_cmd_data(chip) + 1; @@ -515,8 +554,10 @@ static int reset_xd(struct rtsx_chip *chip) continue; retval = xd_read_id(chip, READ_ID, id_buf, 4); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } dev_dbg(rtsx_dev(chip), "READ_ID: 0x%x 0x%x 0x%x 0x%x\n", id_buf[0], id_buf[1], id_buf[2], id_buf[3]); @@ -596,8 +637,10 @@ static int reset_xd(struct rtsx_chip *chip) /* Confirm timing setting */ for (j = 0; j < 10; j++) { retval = xd_read_id(chip, READ_ID, id_buf, 4); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (id_buf[1] != xd_card->device_code) break; @@ -613,23 +656,30 @@ static int reset_xd(struct rtsx_chip *chip) xd_card->addr_cycle = 0; xd_card->capacity = 0; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = xd_read_id(chip, READ_xD_ID, id_buf, 4); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } dev_dbg(rtsx_dev(chip), "READ_xD_ID: 0x%x 0x%x 0x%x 0x%x\n", id_buf[0], id_buf[1], id_buf[2], id_buf[3]); - if (id_buf[2] != XD_ID_CODE) - TRACE_RET(chip, STATUS_FAIL); + if (id_buf[2] != XD_ID_CODE) { + rtsx_trace(chip); + return STATUS_FAIL; + } /* Search CIS block */ for (i = 0; i < 24; i++) { u32 page_addr; - if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } page_addr = (u32)i << xd_card->block_shift; @@ -667,8 +717,10 @@ static int reset_xd(struct rtsx_chip *chip) page_addr += j; retval = xd_read_cis(chip, page_addr, buf, 10); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if ((buf[0] == 0x01) && (buf[1] == 0x03) && (buf[2] == 0xD9) @@ -684,8 +736,10 @@ static int reset_xd(struct rtsx_chip *chip) } dev_dbg(rtsx_dev(chip), "CIS block: 0x%x\n", xd_card->cis_block); - if (xd_card->cis_block == 0xFFFF) - TRACE_RET(chip, STATUS_FAIL); + if (xd_card->cis_block == 0xFFFF) { + rtsx_trace(chip); + return STATUS_FAIL; + } chip->capacity[chip->card2lun[XD_CARD]] = xd_card->capacity; @@ -739,15 +793,19 @@ static int xd_init_l2p_tbl(struct rtsx_chip *chip) dev_dbg(rtsx_dev(chip), "xd_init_l2p_tbl: zone_cnt = %d\n", xd_card->zone_cnt); - if (xd_card->zone_cnt < 1) - TRACE_RET(chip, STATUS_FAIL); + if (xd_card->zone_cnt < 1) { + rtsx_trace(chip); + return STATUS_FAIL; + } size = xd_card->zone_cnt * sizeof(struct zone_entry); dev_dbg(rtsx_dev(chip), "Buffer size for l2p table is %d\n", size); xd_card->zone = vmalloc(size); - if (!xd_card->zone) - TRACE_RET(chip, STATUS_ERROR); + if (!xd_card->zone) { + rtsx_trace(chip); + return STATUS_ERROR; + } for (i = 0; i < xd_card->zone_cnt; i++) { xd_card->zone[i].build_flag = 0; @@ -927,16 +985,22 @@ int reset_xd_card(struct rtsx_chip *chip) xd_card->delay_write.delay_write_flag = 0; retval = enable_card_clock(chip, XD_CARD); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = reset_xd(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } retval = xd_init_l2p_tbl(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -950,8 +1014,10 @@ static int xd_mark_bad_block(struct rtsx_chip *chip, u32 phy_blk) dev_dbg(rtsx_dev(chip), "mark block 0x%x as bad block\n", phy_blk); - if (phy_blk == BLK_NOT_FOUND) - TRACE_RET(chip, STATUS_FAIL); + if (phy_blk == BLK_NOT_FOUND) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -986,7 +1052,8 @@ static int xd_mark_bad_block(struct rtsx_chip *chip, u32 phy_blk) xd_set_err_code(chip, XD_PRG_ERROR); else xd_set_err_code(chip, XD_TO_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -1002,10 +1069,14 @@ static int xd_init_page(struct rtsx_chip *chip, u32 phy_blk, dev_dbg(rtsx_dev(chip), "Init block 0x%x\n", phy_blk); - if (start_page > end_page) - TRACE_RET(chip, STATUS_FAIL); - if (phy_blk == BLK_NOT_FOUND) - TRACE_RET(chip, STATUS_FAIL); + if (start_page > end_page) { + rtsx_trace(chip); + return STATUS_FAIL; + } + if (phy_blk == BLK_NOT_FOUND) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -1040,7 +1111,8 @@ static int xd_init_page(struct rtsx_chip *chip, u32 phy_blk, } else { xd_set_err_code(chip, XD_TO_ERROR); } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -1057,11 +1129,15 @@ static int xd_copy_page(struct rtsx_chip *chip, u32 old_blk, u32 new_blk, dev_dbg(rtsx_dev(chip), "Copy page from block 0x%x to block 0x%x\n", old_blk, new_blk); - if (start_page > end_page) - TRACE_RET(chip, STATUS_FAIL); + if (start_page > end_page) { + rtsx_trace(chip); + return STATUS_FAIL; + } - if ((old_blk == BLK_NOT_FOUND) || (new_blk == BLK_NOT_FOUND)) - TRACE_RET(chip, STATUS_FAIL); + if ((old_blk == BLK_NOT_FOUND) || (new_blk == BLK_NOT_FOUND)) { + rtsx_trace(chip); + return STATUS_FAIL; + } old_page = (old_blk << xd_card->block_shift) + start_page; new_page = (new_blk << xd_card->block_shift) + start_page; @@ -1074,7 +1150,8 @@ static int xd_copy_page(struct rtsx_chip *chip, u32 old_blk, u32 new_blk, if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { rtsx_clear_xd_error(chip); xd_set_err_code(chip, XD_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } rtsx_init_cmd(chip); @@ -1100,7 +1177,8 @@ static int xd_copy_page(struct rtsx_chip *chip, u32 old_blk, u32 new_blk, if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { xd_set_err_code(chip, XD_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (((reg & (XD_ECC1_ERROR | XD_ECC1_UNCORRECTABLE)) == @@ -1119,7 +1197,8 @@ static int xd_copy_page(struct rtsx_chip *chip, u32 old_blk, u32 new_blk, } } else { xd_set_err_code(chip, XD_TO_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1147,7 +1226,8 @@ static int xd_copy_page(struct rtsx_chip *chip, u32 old_blk, u32 new_blk, } else { xd_set_err_code(chip, XD_TO_ERROR); } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } old_page++; @@ -1172,14 +1252,17 @@ static int xd_reset_cmd(struct rtsx_chip *chip) rtsx_add_cmd(chip, READ_REG_CMD, XD_CTL, 0, 0); retval = rtsx_send_cmd(chip, XD_CARD, 100); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } ptr = rtsx_get_cmd_data(chip) + 1; if (((ptr[0] & READY_FLAG) == READY_STATE) && (ptr[1] & XD_RDY)) return STATUS_SUCCESS; - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } static int xd_erase_block(struct rtsx_chip *chip, u32 phy_blk) @@ -1189,8 +1272,10 @@ static int xd_erase_block(struct rtsx_chip *chip, u32 phy_blk) u8 reg = 0, *ptr; int i, retval; - if (phy_blk == BLK_NOT_FOUND) - TRACE_RET(chip, STATUS_FAIL); + if (phy_blk == BLK_NOT_FOUND) { + rtsx_trace(chip); + return STATUS_FAIL; + } page_addr = phy_blk << xd_card->block_shift; @@ -1212,13 +1297,16 @@ static int xd_erase_block(struct rtsx_chip *chip, u32 phy_blk) if (reg & PROGRAM_ERROR) { xd_mark_bad_block(chip, phy_blk); xd_set_err_code(chip, XD_PRG_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } else { xd_set_err_code(chip, XD_ERASE_FAIL); } retval = xd_reset_cmd(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } continue; } @@ -1226,7 +1314,8 @@ static int xd_erase_block(struct rtsx_chip *chip, u32 phy_blk) if (*ptr & PROGRAM_ERROR) { xd_mark_bad_block(chip, phy_blk); xd_set_err_code(chip, XD_PRG_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } return STATUS_SUCCESS; @@ -1234,7 +1323,8 @@ static int xd_erase_block(struct rtsx_chip *chip, u32 phy_blk) xd_mark_bad_block(chip, phy_blk); xd_set_err_code(chip, XD_ERASE_FAIL); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } @@ -1266,15 +1356,19 @@ static int xd_build_l2p_tbl(struct rtsx_chip *chip, int zone_no) if (zone->l2p_table == NULL) { zone->l2p_table = vmalloc(2000); - if (zone->l2p_table == NULL) - TRACE_GOTO(chip, Build_Fail); + if (zone->l2p_table == NULL) { + rtsx_trace(chip); + goto Build_Fail; + } } memset((u8 *)(zone->l2p_table), 0xff, 2000); if (zone->free_table == NULL) { zone->free_table = vmalloc(XD_FREE_TABLE_CNT * 2); - if (zone->free_table == NULL) - TRACE_GOTO(chip, Build_Fail); + if (zone->free_table == NULL) { + rtsx_trace(chip); + goto Build_Fail; + } } memset((u8 *)(zone->free_table), 0xff, XD_FREE_TABLE_CNT * 2); @@ -1440,8 +1534,10 @@ static int xd_send_cmd(struct rtsx_chip *chip, u8 cmd) XD_TRANSFER_END, XD_TRANSFER_END); retval = rtsx_send_cmd(chip, XD_CARD, 200); - if (retval < 0) - TRACE_RET(chip, STATUS_FAIL); + if (retval < 0) { + rtsx_trace(chip); + return STATUS_FAIL; + } return STATUS_SUCCESS; } @@ -1457,8 +1553,10 @@ static int xd_read_multiple_pages(struct rtsx_chip *chip, u32 phy_blk, u8 reg_val, page_cnt; int zone_no, retval, i; - if (start_page > end_page) - TRACE_RET(chip, STATUS_FAIL); + if (start_page > end_page) { + rtsx_trace(chip); + return STATUS_FAIL; + } page_cnt = end_page - start_page; zone_no = (int)(log_blk / 1000); @@ -1474,7 +1572,8 @@ static int xd_read_multiple_pages(struct rtsx_chip *chip, u32 phy_blk, if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { xd_set_err_code(chip, XD_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } } @@ -1509,9 +1608,11 @@ static int xd_read_multiple_pages(struct rtsx_chip *chip, u32 phy_blk, if (retval == -ETIMEDOUT) { xd_set_err_code(chip, XD_TO_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } else { - TRACE_GOTO(chip, Fail); + rtsx_trace(chip); + goto Fail; } } @@ -1533,7 +1634,8 @@ Fail: if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { xd_set_err_code(chip, XD_NO_CARD); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } xd_set_err_code(chip, XD_ECC_ERROR); @@ -1541,7 +1643,8 @@ Fail: new_blk = xd_get_unused_block(chip, zone_no); if (new_blk == NO_NEW_BLK) { XD_CLR_BAD_OLDBLK(xd_card); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = xd_copy_page(chip, phy_blk, new_blk, 0, @@ -1555,7 +1658,8 @@ Fail: XD_CLR_BAD_NEWBLK(xd_card); } XD_CLR_BAD_OLDBLK(xd_card); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } xd_set_l2p_tbl(chip, zone_no, log_off, (u16)(new_blk & 0x3FF)); xd_erase_block(chip, phy_blk); @@ -1563,7 +1667,8 @@ Fail: XD_CLR_BAD_OLDBLK(xd_card); } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } static int xd_finish_write(struct rtsx_chip *chip, @@ -1576,8 +1681,10 @@ static int xd_finish_write(struct rtsx_chip *chip, dev_dbg(rtsx_dev(chip), "xd_finish_write, old_blk = 0x%x, new_blk = 0x%x, log_blk = 0x%x\n", old_blk, new_blk, log_blk); - if (page_off > xd_card->page_off) - TRACE_RET(chip, STATUS_FAIL); + if (page_off > xd_card->page_off) { + rtsx_trace(chip); + return STATUS_FAIL; + } zone_no = (int)(log_blk / 1000); log_off = (u16)(log_blk % 1000); @@ -1589,7 +1696,8 @@ static int xd_finish_write(struct rtsx_chip *chip, retval = xd_erase_block(chip, new_blk); if (retval == STATUS_SUCCESS) xd_set_unused_block(chip, new_blk); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } else { retval = xd_copy_page(chip, old_blk, new_blk, @@ -1601,7 +1709,8 @@ static int xd_finish_write(struct rtsx_chip *chip, xd_set_unused_block(chip, new_blk); } XD_CLR_BAD_NEWBLK(xd_card); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = xd_erase_block(chip, old_blk); @@ -1633,8 +1742,10 @@ static int xd_prepare_write(struct rtsx_chip *chip, if (page_off) { retval = xd_copy_page(chip, old_blk, new_blk, 0, page_off); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -1655,8 +1766,10 @@ static int xd_write_multiple_pages(struct rtsx_chip *chip, u32 old_blk, dev_dbg(rtsx_dev(chip), "%s, old_blk = 0x%x, new_blk = 0x%x, log_blk = 0x%x\n", __func__, old_blk, new_blk, log_blk); - if (start_page > end_page) - TRACE_RET(chip, STATUS_FAIL); + if (start_page > end_page) { + rtsx_trace(chip); + return STATUS_FAIL; + } page_cnt = end_page - start_page; zone_no = (int)(log_blk / 1000); @@ -1665,8 +1778,10 @@ static int xd_write_multiple_pages(struct rtsx_chip *chip, u32 old_blk, page_addr = (new_blk << xd_card->block_shift) + start_page; retval = xd_send_cmd(chip, READ1_1); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } rtsx_init_cmd(chip); @@ -1701,9 +1816,11 @@ static int xd_write_multiple_pages(struct rtsx_chip *chip, u32 old_blk, if (retval == -ETIMEDOUT) { xd_set_err_code(chip, XD_TO_ERROR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } else { - TRACE_GOTO(chip, Fail); + rtsx_trace(chip); + goto Fail; } } @@ -1736,7 +1853,8 @@ Fail: xd_mark_bad_block(chip, new_blk); } - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #ifdef XD_DELAY_WRITE @@ -1749,16 +1867,20 @@ int xd_delay_write(struct rtsx_chip *chip) if (delay_write->delay_write_flag) { dev_dbg(rtsx_dev(chip), "xd_delay_write\n"); retval = xd_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } delay_write->delay_write_flag = 0; retval = xd_finish_write(chip, delay_write->old_phyblock, delay_write->new_phyblock, delay_write->logblock, delay_write->pageoff); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } } return STATUS_SUCCESS; @@ -1790,14 +1912,17 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, ptr = (u8 *)scsi_sglist(srb); retval = xd_switch_clock(chip); - if (retval != STATUS_SUCCESS) - TRACE_RET(chip, STATUS_FAIL); + if (retval != STATUS_SUCCESS) { + rtsx_trace(chip); + return STATUS_FAIL; + } if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { chip->card_fail |= XD_CARD; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } log_blk = start_sector >> xd_card->block_shift; @@ -1810,7 +1935,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (retval != STATUS_SUCCESS) { chip->card_fail |= XD_CARD; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1828,7 +1954,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } old_blk = delay_write->old_phyblock; @@ -1844,7 +1971,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #endif old_blk = xd_get_l2p_tbl(chip, zone_no, log_off); @@ -1853,7 +1981,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, (new_blk == BLK_NOT_FOUND)) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = xd_prepare_write(chip, old_blk, new_blk, @@ -1863,11 +1992,13 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #ifdef XD_DELAY_WRITE } @@ -1879,11 +2010,13 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #endif @@ -1891,7 +2024,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (old_blk == BLK_NOT_FOUND) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1901,7 +2035,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { chip->card_fail |= XD_CARD; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if ((start_page + total_sec_cnt) > (xd_card->page_off + 1)) @@ -1917,7 +2052,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } else { retval = xd_write_multiple_pages(chip, old_blk, @@ -1927,7 +2063,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (retval != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1948,7 +2085,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, chip->card_fail |= XD_CARD; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1961,7 +2099,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } if (srb->sc_data_direction == DMA_TO_DEVICE) { @@ -1969,7 +2108,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (new_blk == BLK_NOT_FOUND) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } } @@ -1988,7 +2128,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { chip->card_fail |= XD_CARD; set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } retval = xd_finish_write(chip, old_blk, new_blk, @@ -1997,10 +2138,12 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip, if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } set_sense_type(chip, lun, SENSE_TYPE_MEDIA_WRITE_ERR); - TRACE_RET(chip, STATUS_FAIL); + rtsx_trace(chip); + return STATUS_FAIL; } #endif } @@ -2049,23 +2192,29 @@ int xd_power_off_card3v3(struct rtsx_chip *chip) int retval; retval = disable_card_clock(chip, XD_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, XD_OUTPUT_EN, 0); if (!chip->ft2_fast_mode) { retval = card_power_off(chip, XD_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 = xd_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, 0xFF, 0xDF); } @@ -2087,8 +2236,10 @@ int release_xd_card(struct rtsx_chip *chip) xd_free_l2p_tbl(chip); retval = xd_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; }