Skip to content

Commit 7f970c4

Browse files
author
Jerry Fan
committed
Support Realtek usb to ssd bridge ic
- Support usb to ssd bridge ic, including RTL9210/RTL9201/RTL9220.
1 parent 7495e97 commit 7f970c4

20 files changed

Lines changed: 1943 additions & 0 deletions
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*
2+
* BSD-3-Clause
3+
*
4+
* Copyright (c) 2022 - 2024, Realtek Semiconductor Corp. All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without modification,
7+
* are permitted provided that the following conditions are met:
8+
*
9+
* * Redistributions of source code must retain the above copyright notice, this
10+
* list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of the Realtek nor the names of its contributors may
17+
* be used to endorse or promote products derived from this software without
18+
* specific prior written permission.
19+
*
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
25+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30+
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
#ifndef _BRIDGE_DEV_H_
34+
#define _BRIDGE_DEV_H_
35+
36+
#ifdef __cplusplus
37+
extern "C" {
38+
#endif
39+
40+
#define NAME_STR_LEN 512
41+
#define MAX_BLK_SIZE 4096
42+
43+
struct identify_info {
44+
// IDENTIFY information
45+
uint8_t serial_num[20];
46+
uint8_t null0; // make sn a cstring
47+
uint8_t fw_rev[8];
48+
uint8_t null1; // make firmware rev a cstring
49+
uint8_t model_num[40];
50+
uint8_t null2; // make model number a cstring
51+
};
52+
53+
struct discovery_info {
54+
uint8_t tper : 1;
55+
uint8_t locking : 1;
56+
uint8_t geometry : 1;
57+
uint8_t single_user_mode : 1;
58+
uint8_t opalv10 : 1;
59+
uint8_t opalv20 : 1;
60+
uint8_t pyritev100 : 1;
61+
uint8_t pyritev200 : 1;
62+
uint8_t blocksid : 1;
63+
uint8_t tper_ack_nack : 1;
64+
uint8_t tper_async : 1;
65+
uint8_t tper_buffer_mgt : 1;
66+
uint8_t tper_comid_mgt : 1;
67+
uint8_t tper_streaming : 1;
68+
uint8_t tper_sync : 1;
69+
uint8_t locking_locked : 1;
70+
uint8_t locking_locking_enabled : 1;
71+
uint8_t locking_locking_supported : 1;
72+
uint8_t locking_mbr_not_supported : 1;
73+
uint8_t locking_mbr_done : 1;
74+
uint8_t locking_mbr_enabled : 1;
75+
uint8_t locking_media_encrypt : 1;
76+
uint8_t geometry_align : 1;
77+
uint8_t blocksid_sid_value : 1;
78+
uint8_t blocksid_sid_block : 1;
79+
uint8_t blocksid_hw_reset : 1;
80+
uint8_t single_user_mode_any : 1;
81+
uint8_t single_user_mode_all : 1;
82+
uint8_t single_user_mode_policy : 1;
83+
uint8_t ruby100 : 1;
84+
uint8_t reserved0 : 2;
85+
uint32_t reserved1;
86+
uint64_t geometry_alignment_granularity;
87+
uint32_t geometry_logical_blocksize;
88+
uint16_t enc_mode;
89+
uint16_t reserved2;
90+
uint64_t geometry_lowest_aligned_lba;
91+
uint32_t single_user_mode_locking_objects;
92+
uint16_t opalv10_base_comid;
93+
uint16_t opalv10_num_comids;
94+
uint16_t base_comid;
95+
uint16_t num_comids;
96+
uint8_t initial_pin;
97+
uint8_t reverted_pin;
98+
uint16_t num_admins;
99+
uint16_t num_users;
100+
uint8_t range_crossing : 1;
101+
uint8_t reserved3 : 7;
102+
uint8_t reserved4;
103+
uint16_t pyritev100_base_comid;
104+
uint16_t pyritev100_num_comids;
105+
uint16_t pyritev100_initial_pin;
106+
uint16_t pyritev100_reverted_pin;
107+
uint16_t pyritev200_base_comid;
108+
uint16_t pyritev200_num_comids;
109+
uint16_t pyritev200_initial_pin;
110+
uint16_t pyritev200_reverted_pin;
111+
uint32_t reserved5;
112+
};
113+
114+
/* ata security info */
115+
struct ata_sec_info {
116+
uint16_t supported : 1;
117+
uint16_t enabled : 1;
118+
uint16_t locked : 1;
119+
uint16_t frozen : 1;
120+
uint16_t expired : 1;
121+
uint16_t enh_sec_erase_supported : 1;
122+
uint16_t reserved00 : 2;
123+
uint16_t master_pwd_cap : 1;
124+
uint16_t reserved01 : 7;
125+
uint16_t master_pwd_id;
126+
uint16_t normal_sec_erase_time;
127+
uint16_t enhanced_sec_erase_time;
128+
};
129+
130+
/** structure to store Disk information. */
131+
struct ssd_info {
132+
struct identify_info identify;
133+
struct discovery_info discovery;
134+
struct ata_sec_info ata_sec;
135+
};
136+
137+
struct scan_result {
138+
char name[NAME_STR_LEN];
139+
char br_name[NAME_STR_LEN];
140+
struct ssd_info ssdinfo;
141+
#if defined(__APPLE__)
142+
char bsd_name[NAME_STR_LEN];
143+
#endif
144+
struct scan_result *next;
145+
};
146+
147+
struct bridge_device_;
148+
typedef struct bridge_device_ bridge_device;
149+
150+
bridge_device *bridge_open_handle(char *dev_path);
151+
int bridge_close_handle(bridge_device *fd);
152+
void bridge_exit();
153+
struct scan_result *bridge_disk_scan(struct usb_id *id, int id_num);
154+
struct scan_result *bridge_dev_scan(struct usb_id *id, int id_num);
155+
void bridge_free_scan(struct scan_result *result);
156+
void* bridge_dev_get_handle(bridge_device *dev);
157+
void bridge_dev_set_disk_blk_size(bridge_device *dev, uint32_t blk_size);
158+
159+
#ifdef __cplusplus
160+
}
161+
#endif
162+
163+
#endif /* _BRIDGE_DEV_H_ */
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
* BSD-3-Clause
3+
*
4+
* Copyright (c) 2022 - 2024, Realtek Semiconductor Corp. All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without modification,
7+
* are permitted provided that the following conditions are met:
8+
*
9+
* * Redistributions of source code must retain the above copyright notice, this
10+
* list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of the Realtek nor the names of its contributors may
17+
* be used to endorse or promote products derived from this software without
18+
* specific prior written permission.
19+
*
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
25+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30+
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
#ifndef _BRIDGE_FUNC_H_
34+
#define _BRIDGE_FUNC_H_
35+
36+
#ifdef __cplusplus
37+
extern "C" {
38+
#endif
39+
40+
#ifndef ARRAY_SIZE
41+
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
42+
#endif
43+
44+
#define MAX_DISKS 10
45+
46+
#ifdef CONFIG_ARGB_DEV
47+
#define M_BRIDGE_CHECK_VID_PID argb_bridge_check_vid_pid
48+
#define M_BRIDGE_WRITE_UNLOCK argb_bridge_write_unlock
49+
#define M_BRIDGE_DISCONNECT argb_bridge_disconnect
50+
#define M_BRIDGE_CHECK_TARGET argb_bridge_check_target
51+
#define M_BRIDGE_GET_IC_GEN argb_bridge_get_ic_gen
52+
#define M_BRIDGE_GET_UUID argb_bridge_get_uuid
53+
#define M_BRIDGE_GET_CUST_PAGE argb_bridge_get_cust_page
54+
#define M_BRIDGE_SET_CUST_PAGE argb_bridge_set_cust_page
55+
#define M_BRIDGE_GET_FW_VER argb_bridge_get_fw_ver
56+
#define M_BRIDGE_GET_BUF_SIZE argb_bridge_get_buf_size
57+
#define M_BRIDGE_GET_USB_SPEED argb_bridge_get_usb_speed
58+
#define M_BRIDGE_GET_API_VER argb_bridge_get_api_ver
59+
#define M_BRIDGE_INQUIRY argb_bridge_inquiry
60+
#define M_BRIDGE_GET_NAME argb_bridge_get_name
61+
#define M_BRIDGE_GET_VENDOR_NAME argb_bridge_get_vendor_name
62+
#define M_BRIDGE_GET_PRODUCT_NAME argb_bridge_get_product_name
63+
#define M_BRIDGE_GET_DEBUG_LEVEL argb_bridge_get_debug_level
64+
#define M_BRIDGE_SET_DEBUG_LEVEL argb_bridge_set_debug_level
65+
#define M_BRIDGE_REPORT_LUNS argb_bridge_report_luns
66+
#else
67+
#define M_BRIDGE_CHECK_VID_PID bridge_check_vid_pid
68+
#define M_BRIDGE_WRITE_UNLOCK bridge_write_unlock
69+
#define M_BRIDGE_DISCONNECT bridge_disconnect
70+
#define M_BRIDGE_CHECK_TARGET bridge_check_target
71+
#define M_BRIDGE_GET_IC_GEN bridge_get_ic_gen
72+
#define M_BRIDGE_GET_UUID bridge_get_uuid
73+
#define M_BRIDGE_GET_CUST_PAGE bridge_get_cust_page
74+
#define M_BRIDGE_SET_CUST_PAGE bridge_set_cust_page
75+
#define M_BRIDGE_GET_FW_VER bridge_get_fw_ver
76+
#define M_BRIDGE_GET_BUF_SIZE bridge_get_buf_size
77+
#define M_BRIDGE_GET_USB_SPEED bridge_get_usb_speed
78+
#define M_BRIDGE_GET_API_VER bridge_get_api_ver
79+
#define M_BRIDGE_INQUIRY bridge_inquiry
80+
#define M_BRIDGE_GET_NAME bridge_get_name
81+
#define M_BRIDGE_GET_VENDOR_NAME bridge_get_vendor_name
82+
#define M_BRIDGE_GET_PRODUCT_NAME bridge_get_product_name
83+
#define M_BRIDGE_GET_DEBUG_LEVEL bridge_get_debug_level
84+
#define M_BRIDGE_SET_DEBUG_LEVEL bridge_set_debug_level
85+
#define M_BRIDGE_REPORT_LUNS bridge_report_luns
86+
#endif
87+
88+
struct bridge_fw_version {
89+
uint32_t fw_major_ver;
90+
uint32_t fw_minor_ver;
91+
uint32_t fw_extra_ver;
92+
uint32_t fw_build_ver;
93+
uint32_t fw_build_date;
94+
};
95+
96+
#ifdef CONFIG_ARGB_DEV
97+
int argb_bridge_check_vid_pid(uint16_t vid,
98+
uint16_t pid,
99+
struct usb_id *id,
100+
int id_num);
101+
int argb_bridge_write_unlock(dHandle fd);
102+
int argb_bridge_disconnect(dHandle fd, int type);
103+
int argb_bridge_get_ic_gen(dHandle fd);
104+
bool argb_bridge_check_target(dHandle fd);
105+
int argb_bridge_get_uuid(dHandle fd, uint8_t *uuid);
106+
int argb_bridge_get_cust_page(dHandle fd, uint8_t *cust_page);
107+
int argb_bridge_set_cust_page(dHandle fd, uint8_t *cust_page);
108+
int argb_bridge_get_fw_ver(dHandle fd, struct bridge_fw_version *fw_ver);
109+
int argb_bridge_get_buf_size(dHandle fd, uint32_t *buf_size);
110+
int argb_bridge_get_usb_speed(dHandle fd, uint32_t *speed);
111+
void argb_bridge_get_api_ver(uint32_t *ver_main1,
112+
uint32_t *ver_main2,
113+
uint32_t *ver_sub1,
114+
uint32_t *ver_sub2);
115+
int argb_bridge_inquiry(dHandle fd, uint8_t *buf, uint32_t buflen);
116+
int argb_bridge_get_name(dHandle fd, char *name, uint32_t len);
117+
int argb_bridge_get_vendor_name(dHandle fd, char *name, uint32_t len);
118+
int argb_bridge_get_product_name(dHandle fd, char *name, uint32_t len);
119+
120+
int argb_bridge_get_debug_level(const char *debug, int *lvl);
121+
int argb_bridge_set_debug_level(int lvl);
122+
123+
int argb_bridge_report_luns(dHandle fd,
124+
uint8_t *lun,
125+
uint32_t *total_luns);
126+
#else
127+
int bridge_check_vid_pid(uint16_t vid,
128+
uint16_t pid,
129+
struct usb_id *id,
130+
int id_num);
131+
int bridge_write_unlock(dHandle fd);
132+
int bridge_disconnect(dHandle fd, int type);
133+
int bridge_get_ic_gen(dHandle fd);
134+
bool bridge_check_target(dHandle fd);
135+
int bridge_get_uuid(dHandle fd, uint8_t *uuid);
136+
int bridge_get_cust_page(dHandle fd, uint8_t *cust_page);
137+
int bridge_set_cust_page(dHandle fd, uint8_t *cust_page);
138+
int bridge_get_fw_ver(dHandle fd, struct bridge_fw_version *fw_ver);
139+
int bridge_get_buf_size(dHandle fd, uint32_t *buf_size);
140+
int bridge_get_usb_speed(dHandle fd, uint32_t *speed);
141+
void bridge_get_api_ver(uint32_t *ver_main1,
142+
uint32_t *ver_main2,
143+
uint32_t *ver_sub1,
144+
uint32_t *ver_sub2);
145+
int bridge_inquiry(dHandle fd, uint8_t *buf, uint32_t buflen);
146+
int bridge_get_name(dHandle fd, char *name, uint32_t len);
147+
int bridge_get_vendor_name(dHandle fd, char *name, uint32_t len);
148+
int bridge_get_product_name(dHandle fd, char *name, uint32_t len);
149+
150+
int bridge_get_debug_level(const char *debug, int *lvl);
151+
int bridge_set_debug_level(int lvl);
152+
153+
int bridge_report_luns(dHandle fd,
154+
uint8_t *lun,
155+
uint32_t *total_luns);
156+
#endif
157+
158+
#ifdef __cplusplus
159+
}
160+
#endif
161+
162+
#endif /* _BRIDGE_FUNC_H_ */

0 commit comments

Comments
 (0)