Fix for VMS 5.5-2 for incorrect Inquiry command allocation lengths
[SCSI2SD.git] / software / include / scsi2sd.h
1 //      Copyright (C) 2014 Michael McMaster <michael@codesrc.com>
2 //
3 //      This file is part of SCSI2SD.
4 //
5 //      SCSI2SD is free software: you can redistribute it and/or modify
6 //      it under the terms of the GNU General Public License as published by
7 //      the Free Software Foundation, either version 3 of the License, or
8 //      (at your option) any later version.
9 //
10 //      SCSI2SD is distributed in the hope that it will be useful,
11 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //      GNU General Public License for more details.
14 //
15 //      You should have received a copy of the GNU General Public License
16 //      along with SCSI2SD.  If not, see <http://www.gnu.org/licenses/>.
17 #ifndef scsi2sd_h
18 #define scsi2sd_h
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 /* Common type definitions shared between the firmware and config tools
25
26         The configuration data is stored in flash.
27
28         The flash is organised as 2 arrays of 256 rows, with each row
29         having 256 bytes. Total of 128kb.
30
31         Linear flash memory map:
32         -----------------------------------------
33         Array 1 |Row 255 | Bootloader metadata
34                         ---------------------------------
35                         |Row 254 |
36                         |Row 252 | Blank
37                         ---------------------------------
38                         |Row 251 |
39                         | ...    |
40                         |Row 236 | Config target 3
41                         | ...    |
42                         |Row 220 | Config target 2
43                         | ...    |
44                         |Row 204 | Config target 1
45                         | ...    |
46                         |Row 188 | Config target 0
47                         ---------------------------------
48                         |Row 187 | Board Config
49                         | ...    | Empty
50                         |Row 172 | Empty
51                         ---------------------------------
52                         |Row 171 |
53                         | ...    |
54                         |Row 156 | Config target 6
55                         | ...    |
56                         |Row 140 | Config target 5
57                         | ...    |
58                         |Row 124 | Config target 4
59                         ---------------------------------
60                         |Row 123 |
61                         | ...    |
62                         |Row 0   |
63         --------|        |
64         Array 0 |Row 255 | Blank
65                         ---------------------------------
66                         |Row 121 |
67                         | ...    |
68                         |Row 37  | Application
69                         ---------------------------------
70                         |Row 36  |
71                         | ...    |
72                         |Row 0   | Bootloader
73
74 */
75
76 #include "stdint.h"
77
78 //#define MAX_SCSI_TARGETS 7
79 #define MAX_SCSI_TARGETS 4
80 #define SCSI_CONFIG_ARRAY 1
81 #define SCSI_CONFIG_ROWS 16
82
83 // 256 bytes data, 32 bytes ECC
84 #define SCSI_CONFIG_ROW_SIZE 256
85 #define SCSI_CONFIG_ROW_ECC 288
86 #define SCSI_CONFIG_BOARD_ROW 187
87 #define SCSI_CONFIG_0_ROW 188
88 #define SCSI_CONFIG_1_ROW 204
89 #define SCSI_CONFIG_2_ROW 220
90 #define SCSI_CONFIG_3_ROW 236
91 #define SCSI_CONFIG_4_ROW 124
92 #define SCSI_CONFIG_5_ROW 140
93 #define SCSI_CONFIG_6_ROW 156
94
95 typedef enum
96 {
97         CONFIG_TARGET_ID_BITS = 0x07,
98         CONFIG_TARGET_ENABLED = 0x80
99 } CONFIG_TARGET_FLAGS;
100
101 typedef enum
102 {
103         CONFIG_ENABLE_UNIT_ATTENTION = 1,
104         CONFIG_ENABLE_PARITY = 2,
105         CONFIG_ENABLE_SCSI2 = 4,
106         CONFIG_DISABLE_GLITCH = 8,
107         CONFIG_ENABLE_CACHE = 16,
108         CONFIG_ENABLE_DISCONNECT = 32,
109         CONFIG_ENABLE_SEL_LATCH = 64,
110         CONFIG_MAP_LUNS_TO_IDS = 128
111 } CONFIG_FLAGS;
112
113 typedef enum
114 {
115         S2S_CFG_ENABLE_TERMINATOR = 1
116 } CONFIG_FLAGS6;
117
118 typedef enum
119 {
120         CONFIG_FIXED,
121         CONFIG_REMOVEABLE,
122         CONFIG_OPTICAL,
123         CONFIG_FLOPPY_14MB,
124         CONFIG_MO,
125         CONFIG_SEQUENTIAL
126
127 } CONFIG_TYPE;
128
129 typedef enum
130 {
131         CONFIG_QUIRKS_NONE = 0,
132         CONFIG_QUIRKS_APPLE = 1,
133         CONFIG_QUIRKS_OMTI = 2,
134         CONFIG_QUIRKS_XEBEC = 4,
135         CONFIG_QUIRKS_VMS = 8
136 } CONFIG_QUIRKS;
137
138 typedef enum
139 {
140         CONFIG_SPEED_NoLimit,
141         CONFIG_SPEED_ASYNC_15
142 } CONFIG_SPEED;
143
144 typedef struct __attribute__((packed))
145 {
146         uint8_t deviceType;
147         uint8_t pageCode;
148         uint8_t reserved;
149         uint8_t pageLength;
150         uint8_t data[0]; // pageLength bytes.
151 } VPD;
152
153 typedef struct __attribute__((packed))
154 {
155         // bits 7 -> 3 = CONFIG_TARGET_FLAGS
156         // bits 2 -> 0 = target SCSI ID.
157         uint8_t scsiId;
158
159         uint8_t deviceType; // CONFIG_TYPE
160         uint8_t flagsDEPRECATED; // CONFIG_FLAGS, removed in v4.5
161         uint8_t deviceTypeModifier; // Used in INQUIRY response.
162
163         uint32_t sdSectorStart;
164         uint32_t scsiSectors;
165
166         uint16_t bytesPerSector;
167
168         // Max allowed by legacy IBM-PC bios is 6 bits (63)
169         uint16_t sectorsPerTrack;
170
171         // MS-Dos up to 7.10 will crash on >= 256 heads.
172         uint16_t headsPerCylinder;
173
174
175         char vendor[8];
176         char prodId[16];
177         char revision[4];
178         char serial[16];
179
180         uint16_t quirks; // CONFIG_QUIRKS
181
182         uint8_t reserved[960]; // Pad out to 1024 bytes for main section.
183
184         uint8_t modePages[1024];
185         uint8_t vpd[1024];
186         uint8_t unused[1024]; // Total size is 4k.
187 } TargetConfig;
188
189 typedef struct __attribute__((packed))
190 {
191         char magic[4]; // 'BCFG'
192         uint8_t flags; // CONFIG_FLAGS
193         uint8_t startupDelay; // Seconds.
194         uint8_t selectionDelay; // milliseconds. 255 = auto
195         uint8_t flags6; // CONFIG_FLAGS6
196
197         uint8_t scsiSpeed;
198
199
200         uint8_t reserved[247]; // Pad out to 256 bytes
201 } BoardConfig;
202
203 typedef enum
204 {
205         CONFIG_NONE, // Invalid
206
207         // Command content:
208         // uint8_t CONFIG_PING
209         // Response:
210         // CONFIG_STATUS
211         CONFIG_PING,
212
213         // Command content:
214         // uint8_t CONFIG_WRITEFLASH
215         // uint8_t[256] flashData
216         // uint8_t flashArray
217         // uint8_t flashRow
218         // Response:
219         // CONFIG_STATUS
220         CONFIG_WRITEFLASH,
221
222         // Command content:
223         // uint8_t CONFIG_READFLASH
224         // uint8_t flashArray
225         // uint8_t flashRow
226         // Response:
227         // 256 bytes of flash
228         CONFIG_READFLASH,
229
230         // Command content:
231         // uint8_t CONFIG_REBOOT
232         // Response: None.
233         CONFIG_REBOOT,
234
235         // Command content:
236         // uint8_t CONFIG_INFO
237         // Response:
238         // uint8_t[16] CSD
239         // uint8_t[16] CID
240         CONFIG_SDINFO,
241
242         // Command content:
243         // uint8_t CONFIG_SCSITEST
244         // Response:
245         // CONFIG_STATUS
246         // uint8_t result code (0 = passed)
247         CONFIG_SCSITEST
248 } CONFIG_COMMAND;
249
250 typedef enum
251 {
252         CONFIG_STATUS_GOOD,
253         CONFIG_STATUS_ERR
254 } CONFIG_STATUS;
255
256
257
258
259 #ifdef __cplusplus
260 } // extern "C"
261
262         #include <type_traits>
263         static_assert(
264                 std::is_pod<TargetConfig>::value, "Misuse of TargetConfig struct"
265                 );
266         static_assert(
267                 sizeof(TargetConfig) == 4096,
268                 "TargetConfig struct size mismatch"
269                 );
270
271 #endif
272
273 #endif