#include <linux/blkdev.h>
#include <linux/kthread.h>
#include <linux/sched.h>
#include <linux/vmalloc.h>
#include "rtsx.h"
#include "ms.h"
static inline void ms_set_err_code(struct rtsx_chip *chip, u8 err_code)
{ … }
static inline int ms_check_err_code(struct rtsx_chip *chip, u8 err_code)
{ … }
static int ms_parse_err_code(struct rtsx_chip *chip)
{ … }
static int ms_transfer_tpc(struct rtsx_chip *chip, u8 trans_mode,
u8 tpc, u8 cnt, u8 cfg)
{ … }
static int ms_transfer_data(struct rtsx_chip *chip, u8 trans_mode,
u8 tpc, u16 sec_cnt, u8 cfg, bool mode_2k,
int use_sg, void *buf, int buf_len)
{ … }
static int ms_write_bytes(struct rtsx_chip *chip,
u8 tpc, u8 cnt, u8 cfg, u8 *data, int data_len)
{ … }
static int ms_read_bytes(struct rtsx_chip *chip,
u8 tpc, u8 cnt, u8 cfg, u8 *data, int data_len)
{ … }
static int ms_set_rw_reg_addr(struct rtsx_chip *chip, u8 read_start,
u8 read_cnt, u8 write_start, u8 write_cnt)
{ … }
static int ms_send_cmd(struct rtsx_chip *chip, u8 cmd, u8 cfg)
{ … }
static int ms_set_init_para(struct rtsx_chip *chip)
{ … }
static int ms_switch_clock(struct rtsx_chip *chip)
{ … }
static int ms_pull_ctl_disable(struct rtsx_chip *chip)
{ … }
static int ms_pull_ctl_enable(struct rtsx_chip *chip)
{ … }
static int ms_prepare_reset(struct rtsx_chip *chip)
{ … }
static int ms_identify_media_type(struct rtsx_chip *chip, int switch_8bit_bus)
{ … }
static int ms_confirm_cpu_startup(struct rtsx_chip *chip)
{ … }
static int ms_switch_parallel_bus(struct rtsx_chip *chip)
{ … }
static int ms_switch_8bit_bus(struct rtsx_chip *chip)
{ … }
static int ms_pro_reset_flow(struct rtsx_chip *chip, int switch_8bit_bus)
{ … }
#ifdef XC_POWERCLASS
static int msxc_change_power(struct rtsx_chip *chip, u8 mode)
{ … }
#endif
static int ms_read_attribute_info(struct rtsx_chip *chip)
{ … }
#ifdef SUPPORT_MAGIC_GATE
static int mg_set_tpc_para_sub(struct rtsx_chip *chip,
int type, u8 mg_entry_num);
#endif
static int reset_ms_pro(struct rtsx_chip *chip)
{ … }
static int ms_read_status_reg(struct rtsx_chip *chip)
{ … }
static int ms_read_extra_data(struct rtsx_chip *chip,
u16 block_addr, u8 page_num, u8 *buf, int buf_len)
{ … }
static int ms_write_extra_data(struct rtsx_chip *chip, u16 block_addr,
u8 page_num, u8 *buf, int buf_len)
{ … }
static int ms_read_page(struct rtsx_chip *chip, u16 block_addr, u8 page_num)
{ … }
static int ms_set_bad_block(struct rtsx_chip *chip, u16 phy_blk)
{ … }
static int ms_erase_block(struct rtsx_chip *chip, u16 phy_blk)
{ … }
static void ms_set_page_status(u16 log_blk, u8 type, u8 *extra, int extra_len)
{ … }
static int ms_init_page(struct rtsx_chip *chip, u16 phy_blk, u16 log_blk,
u8 start_page, u8 end_page)
{ … }
static int ms_copy_page(struct rtsx_chip *chip, u16 old_blk, u16 new_blk,
u16 log_blk, u8 start_page, u8 end_page)
{ … }
static int reset_ms(struct rtsx_chip *chip)
{ … }
static int ms_init_l2p_tbl(struct rtsx_chip *chip)
{ … }
static u16 ms_get_l2p_tbl(struct rtsx_chip *chip, int seg_no, u16 log_off)
{ … }
static void ms_set_l2p_tbl(struct rtsx_chip *chip,
int seg_no, u16 log_off, u16 phy_blk)
{ … }
static void ms_set_unused_block(struct rtsx_chip *chip, u16 phy_blk)
{ … }
static u16 ms_get_unused_block(struct rtsx_chip *chip, int seg_no)
{ … }
static const unsigned short ms_start_idx[] = …;
static int ms_arbitrate_l2p(struct rtsx_chip *chip, u16 phy_blk,
u16 log_off, u8 us1, u8 us2)
{ … }
static int ms_build_l2p_tbl(struct rtsx_chip *chip, int seg_no)
{ … }
int reset_ms_card(struct rtsx_chip *chip)
{ … }
static int mspro_set_rw_cmd(struct rtsx_chip *chip,
u32 start_sec, u16 sec_cnt, u8 cmd)
{ … }
void mspro_stop_seq_mode(struct rtsx_chip *chip)
{ … }
static inline int ms_auto_tune_clock(struct rtsx_chip *chip)
{ … }
static int mspro_rw_multi_sector(struct scsi_cmnd *srb,
struct rtsx_chip *chip, u32 start_sector,
u16 sector_cnt)
{ … }
static int mspro_read_format_progress(struct rtsx_chip *chip,
const int short_data_len)
{ … }
void mspro_polling_format_status(struct rtsx_chip *chip)
{ … }
int mspro_format(struct scsi_cmnd *srb, struct rtsx_chip *chip,
int short_data_len, bool quick_format)
{ … }
static int ms_read_multiple_pages(struct rtsx_chip *chip, u16 phy_blk,
u16 log_blk, u8 start_page, u8 end_page,
u8 *buf, unsigned int *index,
unsigned int *offset)
{ … }
static int ms_write_multiple_pages(struct rtsx_chip *chip, u16 old_blk,
u16 new_blk, u16 log_blk, u8 start_page,
u8 end_page, u8 *buf, unsigned int *index,
unsigned int *offset)
{ … }
static int ms_finish_write(struct rtsx_chip *chip, u16 old_blk, u16 new_blk,
u16 log_blk, u8 page_off)
{ … }
static int ms_prepare_write(struct rtsx_chip *chip, u16 old_blk, u16 new_blk,
u16 log_blk, u8 start_page)
{ … }
#ifdef MS_DELAY_WRITE
int ms_delay_write(struct rtsx_chip *chip)
{ … }
#endif
static inline void ms_rw_fail(struct scsi_cmnd *srb, struct rtsx_chip *chip)
{ … }
static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rtsx_chip *chip,
u32 start_sector, u16 sector_cnt)
{ … }
int ms_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip,
u32 start_sector, u16 sector_cnt)
{ … }
void ms_free_l2p_tbl(struct rtsx_chip *chip)
{ … }
#ifdef SUPPORT_MAGIC_GATE
#ifdef READ_BYTES_WAIT_INT
static int ms_poll_int(struct rtsx_chip *chip)
{ … }
#endif
#ifdef MS_SAMPLE_INT_ERR
static int check_ms_err(struct rtsx_chip *chip)
{ … }
#else
static int check_ms_err(struct rtsx_chip *chip)
{
int retval;
u8 val;
retval = rtsx_read_register(chip, MS_TRANSFER, &val);
if (retval != STATUS_SUCCESS)
return 1;
if (val & MS_TRANSFER_ERR)
return 1;
return 0;
}
#endif
static int mg_send_ex_cmd(struct rtsx_chip *chip, u8 cmd, u8 entry_num)
{ … }
static int mg_set_tpc_para_sub(struct rtsx_chip *chip, int type,
u8 mg_entry_num)
{ … }
int mg_set_leaf_id(struct scsi_cmnd *srb, struct rtsx_chip *chip)
{ … }
int mg_get_local_EKB(struct scsi_cmnd *srb, struct rtsx_chip *chip)
{ … }
int mg_chg(struct scsi_cmnd *srb, struct rtsx_chip *chip)
{ … }
int mg_get_rsp_chg(struct scsi_cmnd *srb, struct rtsx_chip *chip)
{ … }
int mg_rsp(struct scsi_cmnd *srb, struct rtsx_chip *chip)
{ … }
int mg_get_ICV(struct scsi_cmnd *srb, struct rtsx_chip *chip)
{ … }
int mg_set_ICV(struct scsi_cmnd *srb, struct rtsx_chip *chip)
{ … }
#endif
void ms_cleanup_work(struct rtsx_chip *chip)
{ … }
int ms_power_off_card3v3(struct rtsx_chip *chip)
{ … }
int release_ms_card(struct rtsx_chip *chip)
{ … }