The Pedigree Project 0.1
ScsiCommands.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef SCSICOMMANDS_H
21#define SCSICOMMANDS_H
22
23#include "pedigree/kernel/compiler.h"
24#include "pedigree/kernel/processor/types.h"
25
27 public:
29 virtual ~ScsiCommand();
30
31 virtual size_t serialise(uintptr_t& addr) = 0;
32};
33
34namespace ScsiCommands {
35class Inquiry : public ScsiCommand {
36 public:
37 Inquiry(uint16_t len = 0, bool enableVitalData = false, uint8_t pageCode = 0, uint8_t ctl = 0);
38
39 virtual size_t serialise(uintptr_t& addr);
40
41 struct {
42 uint8_t opcode;
43 uint8_t epvd;
44 uint8_t pageCode;
45 uint16_t len;
46 uint8_t control;
47 } PACKED command;
48};
49
50class UnitReady : public ScsiCommand {
51 public:
52 UnitReady(uint8_t ctl = 0);
53
54 virtual size_t serialise(uintptr_t& addr);
55
56 struct {
57 uint8_t opcode;
58 uint32_t rsvd;
59 uint8_t control;
60 } PACKED command;
61};
62
63class ReadSense : public ScsiCommand {
64 public:
65 ReadSense(uint8_t desc, uint8_t len, uint8_t ctl = 0);
66
67 virtual size_t serialise(uintptr_t& addr);
68
69 struct {
70 uint8_t opcode;
71 uint8_t desc;
72 uint16_t rsvd;
73 uint8_t len;
74 uint8_t control;
75 } PACKED command;
76};
77
78class StartStop : public ScsiCommand {
79 public:
80 StartStop(bool imm, uint8_t newpower, bool eject_load, bool start, uint8_t ctl = 0);
81
82 virtual size_t serialise(uintptr_t& addr);
83
84 struct {
85 uint8_t opcode;
86 uint8_t imm;
87 uint16_t rsvd;
88 uint8_t setup;
89 uint8_t control;
90 } PACKED command;
91};
92
94 public:
95 SendDiagnostic(bool selfTest, uint8_t selfTestCode = 0, uintptr_t params = 0, size_t paramLen = 0,
96 bool deviceOffline = false, bool unitOffline = false, uint8_t ctl = 0);
97
98 virtual size_t serialise(uintptr_t& addr);
99
100 struct {
101 uint8_t opcode;
102 uint32_t unitOffline : 1;
103 uint32_t devOffline : 1;
104 uint32_t selfTest : 1;
105 uint32_t rsvd1 : 1;
106 uint32_t pf : 1;
107 uint32_t selfTestCode : 3;
108 uint8_t rsvd2;
109 uint16_t paramListLen;
110 uint8_t control;
111 } PACKED command;
112};
113
115 public:
116 ReadTocCommand(uint16_t nativeBlockSize, uint8_t ctl = 0);
117
118 virtual size_t serialise(uintptr_t& addr);
119
120 struct {
121 uint8_t opcode;
122 uint8_t flags;
123 uint8_t format;
124 uint8_t rsvd1;
125 uint8_t rsvd2;
126 uint8_t rsvd3;
127 uint8_t track;
128 uint16_t len;
129 uint8_t control;
130 } PACKED command;
131
132 struct TocEntry {
133 uint8_t Rsvd1;
134 uint8_t Flags;
135 uint8_t TrackNum;
136 uint8_t Rsvd2;
137 uint32_t TrackStart;
138 } PACKED;
139};
140
142 public:
143 ReadCapacity10(uint8_t ctl = 0);
144
145 virtual size_t serialise(uintptr_t& addr);
146
147 struct {
148 uint8_t opcode;
149 uint8_t obsolete_rsvd;
150 uint32_t lba;
151 uint8_t rsvd[2];
152 uint8_t pmi;
153 uint8_t control;
154 } PACKED command;
155};
156
157class Read10 : public ScsiCommand {
158 public:
159 Read10(uint32_t nLba, uint32_t nSectors);
160
161 virtual size_t serialise(uintptr_t& addr);
162
163 struct command {
164 uint8_t nOpCode;
165 uint8_t bRelAddr : 1;
166 uint8_t res0 : 2;
167 uint8_t bFUA : 1;
168 uint8_t bDPO : 1;
169 uint8_t res1 : 3;
170 uint32_t nLba;
171 uint8_t res2;
172 uint16_t nSectors;
173 uint8_t nControl;
174 } PACKED command;
175};
176
177class Read12 : public ScsiCommand {
178 public:
179 Read12(uint32_t nLba, uint32_t nSectors);
180
181 virtual size_t serialise(uintptr_t& addr);
182
183 struct command {
184 uint8_t nOpCode;
185 uint8_t bRelAddr : 1;
186 uint8_t res0 : 2;
187 uint8_t bFUA : 1;
188 uint8_t bDPO : 1;
189 uint8_t res1 : 3;
190 uint32_t nLba;
191 uint32_t nSectors;
192 uint8_t res2;
193 uint8_t nControl;
194 } PACKED command;
195};
196
197class Read16 : public ScsiCommand {
198 public:
199 Read16(uint64_t nLba, uint32_t nSectors);
200
201 virtual size_t serialise(uintptr_t& addr);
202
203 struct command {
204 uint8_t nOpCode;
205 uint8_t bRelAddr : 1;
206 uint8_t res0 : 2;
207 uint8_t bFUA : 1;
208 uint8_t bDPO : 1;
209 uint8_t res1 : 3;
210 uint64_t nLba;
211 uint32_t nSectors;
212 uint8_t res2;
213 uint8_t nControl;
214 } PACKED command;
215
216 static_assert(sizeof(command) == 16, "READ(16) CDB must be 16 bytes");
217};
218
219class Write10 : public ScsiCommand {
220 public:
221 Write10(uint32_t nLba, uint32_t nSectors);
222
223 virtual size_t serialise(uintptr_t& addr);
224
225 struct command {
226 uint8_t nOpCode;
227 uint8_t obs : 1;
228 uint8_t bFUA_NV : 1;
229 uint8_t res1 : 1;
230 uint8_t bFUA : 1;
231 uint8_t bDPO : 1;
232 uint8_t nWrProtect : 3;
233 uint32_t nLba;
234 uint8_t res2;
235 uint16_t nSectors;
236 uint8_t nControl;
237 } PACKED command;
238};
239
240class Write12 : public ScsiCommand {
241 public:
242 Write12(uint32_t nLba, uint32_t nSectors);
243
244 virtual size_t serialise(uintptr_t& addr);
245
246 struct command {
247 uint8_t nOpCode;
248 uint8_t obs : 1;
249 uint8_t bFUA_NV : 1;
250 uint8_t res1 : 1;
251 uint8_t bFUA : 1;
252 uint8_t bDPO : 1;
253 uint8_t nWrProtect : 3;
254 uint32_t nLba;
255 uint32_t nSectors;
256 uint8_t res2;
257 uint8_t nControl;
258 } PACKED command;
259};
260
261class Write16 : public ScsiCommand {
262 public:
263 Write16(uint64_t nLba, uint32_t nSectors);
264
265 virtual size_t serialise(uintptr_t& addr);
266
267 struct command {
268 uint8_t nOpCode;
269 uint8_t obs : 1;
270 uint8_t bFUA_NV : 1;
271 uint8_t res1 : 1;
272 uint8_t bFUA : 1;
273 uint8_t bDPO : 1;
274 uint8_t nWrProtect : 3;
275 uint64_t nLba;
276 uint32_t nSectors;
277 uint8_t res2;
278 uint8_t nControl;
279 } PACKED command;
280
281 static_assert(sizeof(command) == 16, "WRITE(16) CDB must be 16 bytes");
282};
283
285 public:
286 Synchronise10(uint32_t nLba, uint32_t nSectors);
287
288 virtual size_t serialise(uintptr_t& addr);
289
290 struct command {
291 uint8_t nOpCode;
292 uint8_t obs : 1;
293 uint8_t bImmed : 1;
294 uint8_t bSyncNV : 1;
295 uint8_t rsvd1 : 5;
296 uint32_t nLba;
297 uint8_t nGroup : 5;
298 uint8_t rsvd2 : 3;
299 uint16_t nBlocks;
300 uint8_t nControl;
301 } PACKED command;
302};
303
305 public:
306 Synchronise16(uint64_t nLba, uint32_t nSectors);
307
308 virtual size_t serialise(uintptr_t& addr);
309
310 struct command {
311 uint8_t nOpCode;
312 uint8_t obs : 1;
313 uint8_t bImmed : 1;
314 uint8_t bSyncNV : 1;
315 uint8_t rsvd1 : 5;
316 uint64_t nLba;
317 uint32_t nBlocks;
318 uint8_t nGroup : 5;
319 uint8_t rsvd2 : 3;
320 uint8_t nControl;
321 } PACKED command;
322
323 static_assert(sizeof(command) == 16, "SYNCHRONIZE CACHE(16) CDB must be 16 bytes");
324};
325}; // namespace ScsiCommands
326
327#endif