Revision 0d65e1f8
b/hw/scsi-defs.h | ||
---|---|---|
1 |
/* Copyright (C) 1998, 1999 Free Software Foundation, Inc. |
|
2 |
This file is part of the GNU C Library. |
|
3 |
|
|
4 |
The GNU C Library is free software; you can redistribute it and/or |
|
5 |
modify it under the terms of the GNU Lesser General Public |
|
6 |
License as published by the Free Software Foundation; either |
|
7 |
version 2.1 of the License, or (at your option) any later version. |
|
8 |
|
|
9 |
The GNU C Library is distributed in the hope that it will be useful, |
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 |
Lesser General Public License for more details. |
|
13 |
|
|
14 |
You should have received a copy of the GNU Lesser General Public |
|
15 |
License along with the GNU C Library; if not, write to the Free |
|
16 |
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
|
17 |
02111-1307 USA. */ |
|
18 |
|
|
19 |
/* |
|
20 |
* This header file contains public constants and structures used by |
|
21 |
* the scsi code for linux. |
|
22 |
*/ |
|
23 |
|
|
24 |
/* |
|
25 |
* SCSI opcodes |
|
26 |
*/ |
|
27 |
|
|
28 |
#define TEST_UNIT_READY 0x00 |
|
29 |
#define REZERO_UNIT 0x01 |
|
30 |
#define REQUEST_SENSE 0x03 |
|
31 |
#define FORMAT_UNIT 0x04 |
|
32 |
#define READ_BLOCK_LIMITS 0x05 |
|
33 |
#define REASSIGN_BLOCKS 0x07 |
|
34 |
#define READ_6 0x08 |
|
35 |
#define WRITE_6 0x0a |
|
36 |
#define SEEK_6 0x0b |
|
37 |
#define READ_REVERSE 0x0f |
|
38 |
#define WRITE_FILEMARKS 0x10 |
|
39 |
#define SPACE 0x11 |
|
40 |
#define INQUIRY 0x12 |
|
41 |
#define RECOVER_BUFFERED_DATA 0x14 |
|
42 |
#define MODE_SELECT 0x15 |
|
43 |
#define RESERVE 0x16 |
|
44 |
#define RELEASE 0x17 |
|
45 |
#define COPY 0x18 |
|
46 |
#define ERASE 0x19 |
|
47 |
#define MODE_SENSE 0x1a |
|
48 |
#define START_STOP 0x1b |
|
49 |
#define RECEIVE_DIAGNOSTIC 0x1c |
|
50 |
#define SEND_DIAGNOSTIC 0x1d |
|
51 |
#define ALLOW_MEDIUM_REMOVAL 0x1e |
|
52 |
|
|
53 |
#define SET_WINDOW 0x24 |
|
54 |
#define READ_CAPACITY 0x25 |
|
55 |
#define READ_10 0x28 |
|
56 |
#define WRITE_10 0x2a |
|
57 |
#define SEEK_10 0x2b |
|
58 |
#define WRITE_VERIFY 0x2e |
|
59 |
#define VERIFY 0x2f |
|
60 |
#define SEARCH_HIGH 0x30 |
|
61 |
#define SEARCH_EQUAL 0x31 |
|
62 |
#define SEARCH_LOW 0x32 |
|
63 |
#define SET_LIMITS 0x33 |
|
64 |
#define PRE_FETCH 0x34 |
|
65 |
#define READ_POSITION 0x34 |
|
66 |
#define SYNCHRONIZE_CACHE 0x35 |
|
67 |
#define LOCK_UNLOCK_CACHE 0x36 |
|
68 |
#define READ_DEFECT_DATA 0x37 |
|
69 |
#define MEDIUM_SCAN 0x38 |
|
70 |
#define COMPARE 0x39 |
|
71 |
#define COPY_VERIFY 0x3a |
|
72 |
#define WRITE_BUFFER 0x3b |
|
73 |
#define READ_BUFFER 0x3c |
|
74 |
#define UPDATE_BLOCK 0x3d |
|
75 |
#define READ_LONG 0x3e |
|
76 |
#define WRITE_LONG 0x3f |
|
77 |
#define CHANGE_DEFINITION 0x40 |
|
78 |
#define WRITE_SAME 0x41 |
|
79 |
#define READ_TOC 0x43 |
|
80 |
#define LOG_SELECT 0x4c |
|
81 |
#define LOG_SENSE 0x4d |
|
82 |
#define MODE_SELECT_10 0x55 |
|
83 |
#define RESERVE_10 0x56 |
|
84 |
#define RELEASE_10 0x57 |
|
85 |
#define MODE_SENSE_10 0x5a |
|
86 |
#define PERSISTENT_RESERVE_IN 0x5e |
|
87 |
#define PERSISTENT_RESERVE_OUT 0x5f |
|
88 |
#define MOVE_MEDIUM 0xa5 |
|
89 |
#define READ_12 0xa8 |
|
90 |
#define WRITE_12 0xaa |
|
91 |
#define WRITE_VERIFY_12 0xae |
|
92 |
#define SEARCH_HIGH_12 0xb0 |
|
93 |
#define SEARCH_EQUAL_12 0xb1 |
|
94 |
#define SEARCH_LOW_12 0xb2 |
|
95 |
#define READ_ELEMENT_STATUS 0xb8 |
|
96 |
#define SEND_VOLUME_TAG 0xb6 |
|
97 |
#define WRITE_LONG_2 0xea |
|
98 |
|
|
99 |
/* from hw/scsi-generic.c */ |
|
100 |
#define REWIND 0x01 |
|
101 |
#define REPORT_DENSITY_SUPPORT 0x44 |
|
102 |
#define LOAD_UNLOAD 0xa6 |
|
103 |
#define SET_CD_SPEED 0xbb |
|
104 |
#define BLANK 0xa1 |
|
105 |
|
|
106 |
/* |
|
107 |
* Status codes |
|
108 |
*/ |
|
109 |
|
|
110 |
#define GOOD 0x00 |
|
111 |
#define CHECK_CONDITION 0x01 |
|
112 |
#define CONDITION_GOOD 0x02 |
|
113 |
#define BUSY 0x04 |
|
114 |
#define INTERMEDIATE_GOOD 0x08 |
|
115 |
#define INTERMEDIATE_C_GOOD 0x0a |
|
116 |
#define RESERVATION_CONFLICT 0x0c |
|
117 |
#define COMMAND_TERMINATED 0x11 |
|
118 |
#define QUEUE_FULL 0x14 |
|
119 |
|
|
120 |
#define STATUS_MASK 0x3e |
|
121 |
|
|
122 |
/* |
|
123 |
* SENSE KEYS |
|
124 |
*/ |
|
125 |
|
|
126 |
#define NO_SENSE 0x00 |
|
127 |
#define RECOVERED_ERROR 0x01 |
|
128 |
#define NOT_READY 0x02 |
|
129 |
#define MEDIUM_ERROR 0x03 |
|
130 |
#define HARDWARE_ERROR 0x04 |
|
131 |
#define ILLEGAL_REQUEST 0x05 |
|
132 |
#define UNIT_ATTENTION 0x06 |
|
133 |
#define DATA_PROTECT 0x07 |
|
134 |
#define BLANK_CHECK 0x08 |
|
135 |
#define COPY_ABORTED 0x0a |
|
136 |
#define ABORTED_COMMAND 0x0b |
|
137 |
#define VOLUME_OVERFLOW 0x0d |
|
138 |
#define MISCOMPARE 0x0e |
|
139 |
|
|
140 |
|
|
141 |
/* |
|
142 |
* DEVICE TYPES |
|
143 |
*/ |
|
144 |
|
|
145 |
#define TYPE_DISK 0x00 |
|
146 |
#define TYPE_TAPE 0x01 |
|
147 |
#define TYPE_PROCESSOR 0x03 /* HP scanners use this */ |
|
148 |
#define TYPE_WORM 0x04 /* Treated as ROM by our system */ |
|
149 |
#define TYPE_ROM 0x05 |
|
150 |
#define TYPE_SCANNER 0x06 |
|
151 |
#define TYPE_MOD 0x07 /* Magneto-optical disk - |
|
152 |
* - treated as TYPE_DISK */ |
|
153 |
#define TYPE_MEDIUM_CHANGER 0x08 |
|
154 |
#define TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */ |
|
155 |
#define TYPE_NO_LUN 0x7f |
|
156 |
|
b/hw/scsi-disk.c | ||
---|---|---|
30 | 30 |
#include "qemu-common.h" |
31 | 31 |
#include "block.h" |
32 | 32 |
#include "scsi.h" |
33 |
|
|
34 |
#define SENSE_NO_SENSE 0 |
|
35 |
#define SENSE_NOT_READY 2 |
|
36 |
#define SENSE_HARDWARE_ERROR 4 |
|
37 |
#define SENSE_ILLEGAL_REQUEST 5 |
|
38 |
|
|
39 |
#define STATUS_GOOD 0 |
|
40 |
#define STATUS_CHECK_CONDITION 2 |
|
33 |
#include "scsi-defs.h" |
|
41 | 34 |
|
42 | 35 |
#define SCSI_DMA_BUF_SIZE 131072 |
43 | 36 |
#define SCSI_MAX_INQUIRY_LEN 256 |
... | ... | |
128 | 121 |
if (ret) { |
129 | 122 |
DPRINTF("IO error\n"); |
130 | 123 |
r->req.bus->complete(r->req.bus, SCSI_REASON_DATA, r->req.tag, 0); |
131 |
scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NO_SENSE);
|
|
124 |
scsi_command_complete(r, CHECK_CONDITION, NO_SENSE);
|
|
132 | 125 |
return; |
133 | 126 |
} |
134 | 127 |
DPRINTF("Data ready tag=0x%x len=%" PRId64 "\n", r->req.tag, r->iov.iov_len); |
... | ... | |
147 | 140 |
if (!r) { |
148 | 141 |
BADF("Bad read tag 0x%x\n", tag); |
149 | 142 |
/* ??? This is the wrong error. */ |
150 |
scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR);
|
|
143 |
scsi_command_complete(r, CHECK_CONDITION, HARDWARE_ERROR);
|
|
151 | 144 |
return; |
152 | 145 |
} |
153 | 146 |
if (r->sector_count == (uint32_t)-1) { |
... | ... | |
158 | 151 |
} |
159 | 152 |
DPRINTF("Read sector_count=%d\n", r->sector_count); |
160 | 153 |
if (r->sector_count == 0) { |
161 |
scsi_command_complete(r, STATUS_GOOD, SENSE_NO_SENSE);
|
|
154 |
scsi_command_complete(r, GOOD, NO_SENSE);
|
|
162 | 155 |
return; |
163 | 156 |
} |
164 | 157 |
|
... | ... | |
171 | 164 |
r->req.aiocb = bdrv_aio_readv(s->dinfo->bdrv, r->sector, &r->qiov, n, |
172 | 165 |
scsi_read_complete, r); |
173 | 166 |
if (r->req.aiocb == NULL) |
174 |
scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR);
|
|
167 |
scsi_command_complete(r, CHECK_CONDITION, HARDWARE_ERROR);
|
|
175 | 168 |
r->sector += n; |
176 | 169 |
r->sector_count -= n; |
177 | 170 |
} |
... | ... | |
189 | 182 |
r->status |= SCSI_REQ_STATUS_RETRY; |
190 | 183 |
vm_stop(0); |
191 | 184 |
} else { |
192 |
scsi_command_complete(r, STATUS_CHECK_CONDITION,
|
|
193 |
SENSE_HARDWARE_ERROR);
|
|
185 |
scsi_command_complete(r, CHECK_CONDITION, |
|
186 |
HARDWARE_ERROR); |
|
194 | 187 |
} |
195 | 188 |
|
196 | 189 |
return 1; |
... | ... | |
213 | 206 |
r->sector += n; |
214 | 207 |
r->sector_count -= n; |
215 | 208 |
if (r->sector_count == 0) { |
216 |
scsi_command_complete(r, STATUS_GOOD, SENSE_NO_SENSE);
|
|
209 |
scsi_command_complete(r, GOOD, NO_SENSE);
|
|
217 | 210 |
} else { |
218 | 211 |
len = r->sector_count * 512; |
219 | 212 |
if (len > SCSI_DMA_BUF_SIZE) { |
... | ... | |
236 | 229 |
r->req.aiocb = bdrv_aio_writev(s->dinfo->bdrv, r->sector, &r->qiov, n, |
237 | 230 |
scsi_write_complete, r); |
238 | 231 |
if (r->req.aiocb == NULL) |
239 |
scsi_command_complete(r, STATUS_CHECK_CONDITION,
|
|
240 |
SENSE_HARDWARE_ERROR);
|
|
232 |
scsi_command_complete(r, CHECK_CONDITION, |
|
233 |
HARDWARE_ERROR); |
|
241 | 234 |
} else { |
242 | 235 |
/* Invoke completion routine to fetch data from host. */ |
243 | 236 |
scsi_write_complete(r, 0); |
... | ... | |
255 | 248 |
r = scsi_find_request(s, tag); |
256 | 249 |
if (!r) { |
257 | 250 |
BADF("Bad write tag 0x%x\n", tag); |
258 |
scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR);
|
|
251 |
scsi_command_complete(r, CHECK_CONDITION, HARDWARE_ERROR);
|
|
259 | 252 |
return 1; |
260 | 253 |
} |
261 | 254 |
|
... | ... | |
401 | 394 |
goto fail; |
402 | 395 |
memset(outbuf, 0, 4); |
403 | 396 |
r->iov.iov_len = 4; |
404 |
if (s->sense == SENSE_NOT_READY && len >= 18) {
|
|
397 |
if (s->sense == NOT_READY && len >= 18) { |
|
405 | 398 |
memset(outbuf, 0, 18); |
406 | 399 |
r->iov.iov_len = 18; |
407 | 400 |
outbuf[7] = 10; |
... | ... | |
767 | 760 |
r->iov.iov_len = 8; |
768 | 761 |
} else { |
769 | 762 |
notready: |
770 |
scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NOT_READY);
|
|
763 |
scsi_command_complete(r, CHECK_CONDITION, NOT_READY);
|
|
771 | 764 |
return 0; |
772 | 765 |
} |
773 | 766 |
break; |
... | ... | |
877 | 870 |
/* Protection, exponent and lowest lba field left blank. */ |
878 | 871 |
r->iov.iov_len = len; |
879 | 872 |
} else { |
880 |
scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NOT_READY);
|
|
873 |
scsi_command_complete(r, CHECK_CONDITION, NOT_READY);
|
|
881 | 874 |
return 0; |
882 | 875 |
} |
883 | 876 |
break; |
... | ... | |
898 | 891 |
default: |
899 | 892 |
DPRINTF("Unknown SCSI command (%2.2x)\n", buf[0]); |
900 | 893 |
fail: |
901 |
scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_ILLEGAL_REQUEST);
|
|
894 |
scsi_command_complete(r, CHECK_CONDITION, ILLEGAL_REQUEST);
|
|
902 | 895 |
return 0; |
903 | 896 |
illegal_lba: |
904 |
scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR);
|
|
897 |
scsi_command_complete(r, CHECK_CONDITION, HARDWARE_ERROR);
|
|
905 | 898 |
return 0; |
906 | 899 |
} |
907 | 900 |
if (r->sector_count == 0 && r->iov.iov_len == 0) { |
908 |
scsi_command_complete(r, STATUS_GOOD, SENSE_NO_SENSE);
|
|
901 |
scsi_command_complete(r, GOOD, NO_SENSE);
|
|
909 | 902 |
} |
910 | 903 |
len = r->sector_count * 512 + r->iov.iov_len; |
911 | 904 |
if (is_write) { |
b/hw/scsi-generic.c | ||
---|---|---|
34 | 34 |
#include <sys/stat.h> |
35 | 35 |
#include <unistd.h> |
36 | 36 |
#include <scsi/sg.h> |
37 |
#include <scsi/scsi.h> |
|
38 |
|
|
39 |
#define REWIND 0x01 |
|
40 |
#define REPORT_DENSITY_SUPPORT 0x44 |
|
41 |
#define LOAD_UNLOAD 0xa6 |
|
42 |
#define SET_CD_SPEED 0xbb |
|
43 |
#define BLANK 0xa1 |
|
37 |
#include "scsi-defs.h" |
|
44 | 38 |
|
45 | 39 |
#define SCSI_SENSE_BUF_SIZE 96 |
46 | 40 |
|
Also available in: Unified diff