2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-15 16:53:54 +08:00

staging: rts5208: Remove TRACE_RET and TRACE_GOTO macros

Remove these flow hiding macros.

Miscellanea:

o Add a macro and function to replace a large inline
o Simplify #includes
o Add trace.c and update Makefile
o Remove static inline filename function and use kbasename instead

This reduces object size quite a lot: ~350KB (x86-64 allyesconfig)

$ size drivers/staging/rts5208/built-in.o*
   text	   data	    bss	    dec	    hex	filename
 248385	  36728	  77888	 363001	  589f9	drivers/staging/rts5208/built-in.o.new
 506691	  83352	 115896	 705939	  ac593	drivers/staging/rts5208/built-in.o.old

Done via coccinelle script and some typing.

@@
expression chip;
expression ret;
@@

-	TRACE_RET(chip, ret);
+	rtsx_trace(chip);
+	return ret;

@@
expression chip;
identifier label;
@@

-	TRACE_GOTO(chip, label);
+	rtsx_trace(chip);
+	goto label;

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Joe Perches 2015-03-25 12:54:25 -07:00 committed by Greg Kroah-Hartman
parent da3c8deef6
commit 031366ea65
14 changed files with 2987 additions and 1576 deletions

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -26,12 +26,6 @@
#include <linux/workqueue.h>
#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"

View File

@ -46,9 +46,6 @@
#include <scsi/scsi_eh.h>
#include <scsi/scsi_host.h>
#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 */

View File

@ -27,13 +27,6 @@
#include <linux/kernel.h>
#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;
}

View File

@ -27,13 +27,6 @@
#include <linux/vmalloc.h>
#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, &reg);
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, &reg);
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, &reg);
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;

View File

@ -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 */

File diff suppressed because it is too large Load Diff

View File

@ -25,10 +25,6 @@
#include <linux/sched.h>
#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);

File diff suppressed because it is too large Load Diff

View File

@ -25,9 +25,6 @@
#include <linux/sched.h>
#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;

View File

@ -0,0 +1,26 @@
#include <linux/kernel.h>
#include <linux/string.h>
#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

View File

@ -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)
{
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)
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
#define TRACE_RET(chip, ret) return ret
#define TRACE_GOTO(chip, label) goto label
static inline void rtsx_trace(struct rtsx_chip *chip)
{
}
#endif
#endif /* __REALTEK_RTSX_TRACE_H */

View File

@ -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, &reg);
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, &reg);
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;
}