1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * ms_block.h - Sony MemoryStick (legacy) storage support
5 * Copyright (C) 2013 Maxim Levitsky <maximlevitsky@gmail.com>
7 * Minor portions of the driver are copied from mspro_block.c which is
8 * Copyright (C) 2007 Alex Dubov <oakad@yahoo.com>
10 * Also ms structures were copied from old broken driver by same author
11 * These probably come from MS spec
14 #ifndef MS_BLOCK_NEW_H
15 #define MS_BLOCK_NEW_H
17 #define MS_BLOCK_MAX_SEGS 32
18 #define MS_BLOCK_MAX_PAGES ((2 << 16) - 1)
20 #define MS_BLOCK_MAX_BOOT_ADDR 0x000c
21 #define MS_BLOCK_BOOT_ID 0x0001
22 #define MS_BLOCK_INVALID 0xffff
23 #define MS_MAX_ZONES 16
24 #define MS_BLOCKS_IN_ZONE 512
26 #define MS_BLOCK_MAP_LINE_SZ 16
27 #define MS_BLOCK_PART_SHIFT 3
30 #define MEMSTICK_UNCORR_ERROR (MEMSTICK_STATUS1_UCFG | \
31 MEMSTICK_STATUS1_UCEX | MEMSTICK_STATUS1_UCDT)
33 #define MEMSTICK_CORR_ERROR (MEMSTICK_STATUS1_FGER | MEMSTICK_STATUS1_EXER | \
34 MEMSTICK_STATUS1_DTER)
36 #define MEMSTICK_INT_ERROR (MEMSTICK_INT_CMDNAK | MEMSTICK_INT_ERR)
38 #define MEMSTICK_OVERWRITE_FLAG_NORMAL \
39 (MEMSTICK_OVERWRITE_PGST1 | \
40 MEMSTICK_OVERWRITE_PGST0 | \
41 MEMSTICK_OVERWRITE_BKST)
43 #define MEMSTICK_OV_PG_NORMAL \
44 (MEMSTICK_OVERWRITE_PGST1 | MEMSTICK_OVERWRITE_PGST0)
46 #define MEMSTICK_MANAGEMENT_FLAG_NORMAL \
47 (MEMSTICK_MANAGEMENT_SYSFLG | \
48 MEMSTICK_MANAGEMENT_SCMS1 | \
49 MEMSTICK_MANAGEMENT_SCMS0) \
51 struct ms_boot_header {
52 unsigned short block_id
;
53 unsigned short format_reserved
;
54 unsigned char reserved0
[184];
55 unsigned char data_entry
;
56 unsigned char reserved1
[179];
60 struct ms_system_item
{
61 unsigned int start_addr
;
62 unsigned int data_size
;
63 unsigned char data_type_id
;
64 unsigned char reserved
[3];
67 struct ms_system_entry
{
68 struct ms_system_item disabled_block
;
69 struct ms_system_item cis_idi
;
70 unsigned char reserved
[24];
73 struct ms_boot_attr_info
{
74 unsigned char memorystick_class
;
75 unsigned char format_unique_value1
;
76 unsigned short block_size
;
77 unsigned short number_of_blocks
;
78 unsigned short number_of_effective_blocks
;
79 unsigned short page_size
;
80 unsigned char extra_data_size
;
81 unsigned char format_unique_value2
;
82 unsigned char assembly_time
[8];
83 unsigned char format_unique_value3
;
84 unsigned char serial_number
[3];
85 unsigned char assembly_manufacturer_code
;
86 unsigned char assembly_model_code
[3];
87 unsigned short memory_manufacturer_code
;
88 unsigned short memory_device_code
;
89 unsigned short implemented_capacity
;
90 unsigned char format_unique_value4
[2];
93 unsigned short controller_number
;
94 unsigned short controller_function
;
95 unsigned char reserved0
[9];
96 unsigned char transfer_supporting
;
97 unsigned short format_unique_value5
;
98 unsigned char format_type
;
99 unsigned char memorystick_application
;
100 unsigned char device_type
;
101 unsigned char reserved1
[22];
102 unsigned char format_uniqure_value6
[2];
103 unsigned char reserved2
[15];
107 unsigned short general_config
;
108 unsigned short logical_cylinders
;
109 unsigned short reserved0
;
110 unsigned short logical_heads
;
111 unsigned short track_size
;
112 unsigned short page_size
;
113 unsigned short pages_per_track
;
116 unsigned short reserved1
;
117 unsigned char serial_number
[20];
118 unsigned short buffer_type
;
119 unsigned short buffer_size_increments
;
120 unsigned short long_command_ecc
;
121 unsigned char firmware_version
[28];
122 unsigned char model_name
[18];
123 unsigned short reserved2
[5];
124 unsigned short pio_mode_number
;
125 unsigned short dma_mode_number
;
126 unsigned short field_validity
;
127 unsigned short current_logical_cylinders
;
128 unsigned short current_logical_heads
;
129 unsigned short current_pages_per_track
;
130 unsigned int current_page_capacity
;
131 unsigned short mutiple_page_setting
;
132 unsigned int addressable_pages
;
133 unsigned short single_word_dma
;
134 unsigned short multi_word_dma
;
135 unsigned char reserved3
[128];
139 struct ms_boot_page
{
140 struct ms_boot_header header
;
141 struct ms_system_entry entry
;
142 struct ms_boot_attr_info attr
;
146 unsigned int usage_count
;
147 struct memstick_dev
*card
;
148 struct gendisk
*disk
;
149 struct request_queue
*queue
;
151 struct blk_mq_tag_set tag_set
;
152 struct hd_geometry geometry
;
153 struct attribute_group attr_group
;
159 struct workqueue_struct
*io_queue
;
160 bool io_queue_stopped
;
161 struct work_struct io_work
;
164 /* Media properties */
165 struct ms_boot_page
*boot_page
;
166 u16 boot_block_locations
[2];
167 int boot_block_count
;
170 unsigned short page_size
;
175 int logical_block_count
;
178 unsigned long *used_blocks_bitmap
;
179 unsigned long *erased_blocks_bitmap
;
180 u16
*lba_to_pba_table
;
181 int free_block_count
[MS_MAX_ZONES
];
182 bool ftl_initialized
;
185 unsigned char *cache
;
186 unsigned long valid_cache_bitmap
;
188 bool need_flush_cache
;
189 struct timer_list cache_flush_timer
;
191 /* Preallocated buffers */
192 unsigned char *block_buffer
;
193 struct scatterlist prealloc_sg
[MS_BLOCK_MAX_SEGS
+1];
196 /* handler's local data */
197 struct ms_register_addr reg_addr
;
201 bool command_need_oob
;
202 struct scatterlist
*current_sg
;
203 int current_sg_offset
;
205 struct ms_register regs
;
211 unsigned long int_timeout
;
215 enum msb_readpage_states
{
216 MSB_RP_SEND_BLOCK_ADDRESS
= 0,
217 MSB_RP_SEND_READ_COMMAND
,
220 MSB_RP_RECEIVE_INT_REQ_RESULT
,
222 MSB_RP_SEND_READ_STATUS_REG
,
223 MSB_RP_RECEIVE_STATUS_REG
,
225 MSB_RP_SEND_OOB_READ
,
226 MSB_RP_RECEIVE_OOB_READ
,
228 MSB_RP_SEND_READ_DATA
,
229 MSB_RP_RECEIVE_READ_DATA
,
232 enum msb_write_block_states
{
233 MSB_WB_SEND_WRITE_PARAMS
= 0,
234 MSB_WB_SEND_WRITE_OOB
,
235 MSB_WB_SEND_WRITE_COMMAND
,
238 MSB_WB_RECEIVE_INT_REQ
,
240 MSB_WB_SEND_WRITE_DATA
,
241 MSB_WB_RECEIVE_WRITE_CONFIRMATION
,
244 enum msb_send_command_states
{
245 MSB_SC_SEND_WRITE_PARAMS
,
246 MSB_SC_SEND_WRITE_OOB
,
250 MSB_SC_RECEIVE_INT_REQ
,
254 enum msb_reset_states
{
259 enum msb_par_switch_states
{
260 MSB_PS_SEND_SWITCH_COMMAND
,
272 static int msb_reset(struct msb_data
*msb
, bool full
);
274 static int h_msb_default_bad(struct memstick_dev
*card
,
275 struct memstick_request
**mrq
);
277 #define __dbg(level, format, ...) \
279 if (debug >= level) \
280 pr_err(format "\n", ## __VA_ARGS__); \
284 #define dbg(format, ...) __dbg(1, format, ## __VA_ARGS__)
285 #define dbg_verbose(format, ...) __dbg(2, format, ## __VA_ARGS__)