2 * SCSI Device emulation
4 * Copyright (c) 2006 CodeSourcery.
5 * Based on code by Fabrice Bellard
7 * Written by Paul Brook
9 * This code is licenced under the LGPL.
11 * Note that this file only handles the SCSI architecture model and device
12 * commands. Emulation of interface/link layer protocols is handled by
13 * the host adapter emulator.
16 #include <qemu-common.h>
21 #define DPRINTF(fmt, args...) \
22 do { printf("scsi-disk: " fmt , ##args); } while (0)
24 #define DPRINTF(fmt, args...) do {} while(0)
27 #define BADF(fmt, args...) \
28 do { fprintf(stderr, "scsi-disk: " fmt , ##args); } while (0)
30 #include "qemu-common.h"
32 #include "scsi-disk.h"
34 #define SENSE_NO_SENSE 0
35 #define SENSE_NOT_READY 2
36 #define SENSE_HARDWARE_ERROR 4
37 #define SENSE_ILLEGAL_REQUEST 5
40 #define STATUS_CHECK_CONDITION 2
42 #define SCSI_DMA_BUF_SIZE 131072
43 #define SCSI_MAX_INQUIRY_LEN 256
45 #define SCSI_REQ_STATUS_RETRY 0x01
47 typedef struct SCSIRequest
{
50 /* ??? We should probably keep track of whether the data transfer is
51 a read or a write. Currently we rely on the host getting it right. */
52 /* Both sector and sector_count are in terms of qemu 512 byte blocks. */
54 uint32_t sector_count
;
55 /* The amounnt of data in the buffer. */
58 BlockDriverAIOCB
*aiocb
;
59 struct SCSIRequest
*next
;
63 struct SCSIDeviceState
65 BlockDriverState
*bdrv
;
66 SCSIRequest
*requests
;
67 /* The qemu block layer uses a fixed 512 byte sector size.
68 This is the number of 512 byte blocks in a single scsi sector. */
72 /* Completion functions may be called from either scsi_{read,write}_data
73 or from the AIO completion routines. */
74 scsi_completionfn completion
;
76 char drive_serial_str
[21];
79 /* Global pool of SCSIRequest structures. */
80 static SCSIRequest
*free_requests
= NULL
;
82 static SCSIRequest
*scsi_new_request(SCSIDeviceState
*s
, uint32_t tag
)
88 free_requests
= r
->next
;
90 r
= qemu_malloc(sizeof(SCSIRequest
));
91 r
->dma_buf
= qemu_memalign(512, SCSI_DMA_BUF_SIZE
);
100 r
->next
= s
->requests
;
105 static void scsi_remove_request(SCSIRequest
*r
)
108 SCSIDeviceState
*s
= r
->dev
;
110 if (s
->requests
== r
) {
111 s
->requests
= r
->next
;
114 while (last
&& last
->next
!= r
)
117 last
->next
= r
->next
;
119 BADF("Orphaned request\n");
122 r
->next
= free_requests
;
126 static SCSIRequest
*scsi_find_request(SCSIDeviceState
*s
, uint32_t tag
)
131 while (r
&& r
->tag
!= tag
)
137 /* Helper function for command completion. */
138 static void scsi_command_complete(SCSIRequest
*r
, int status
, int sense
)
140 SCSIDeviceState
*s
= r
->dev
;
142 DPRINTF("Command complete tag=0x%x status=%d sense=%d\n", r
->tag
, status
, sense
);
145 scsi_remove_request(r
);
146 s
->completion(s
->opaque
, SCSI_REASON_DONE
, tag
, status
);
149 /* Cancel a pending data transfer. */
150 static void scsi_cancel_io(SCSIDevice
*d
, uint32_t tag
)
152 SCSIDeviceState
*s
= d
->state
;
154 DPRINTF("Cancel tag=0x%x\n", tag
);
155 r
= scsi_find_request(s
, tag
);
158 bdrv_aio_cancel(r
->aiocb
);
160 scsi_remove_request(r
);
164 static void scsi_read_complete(void * opaque
, int ret
)
166 SCSIRequest
*r
= (SCSIRequest
*)opaque
;
167 SCSIDeviceState
*s
= r
->dev
;
170 DPRINTF("IO error\n");
171 s
->completion(s
->opaque
, SCSI_REASON_DATA
, r
->tag
, 0);
172 scsi_command_complete(r
, STATUS_CHECK_CONDITION
, SENSE_NO_SENSE
);
175 DPRINTF("Data ready tag=0x%x len=%d\n", r
->tag
, r
->buf_len
);
177 s
->completion(s
->opaque
, SCSI_REASON_DATA
, r
->tag
, r
->buf_len
);
180 /* Read more data from scsi device into buffer. */
181 static void scsi_read_data(SCSIDevice
*d
, uint32_t tag
)
183 SCSIDeviceState
*s
= d
->state
;
187 r
= scsi_find_request(s
, tag
);
189 BADF("Bad read tag 0x%x\n", tag
);
190 /* ??? This is the wrong error. */
191 scsi_command_complete(r
, STATUS_CHECK_CONDITION
, SENSE_HARDWARE_ERROR
);
194 if (r
->sector_count
== (uint32_t)-1) {
195 DPRINTF("Read buf_len=%d\n", r
->buf_len
);
197 s
->completion(s
->opaque
, SCSI_REASON_DATA
, r
->tag
, r
->buf_len
);
200 DPRINTF("Read sector_count=%d\n", r
->sector_count
);
201 if (r
->sector_count
== 0) {
202 scsi_command_complete(r
, STATUS_GOOD
, SENSE_NO_SENSE
);
207 if (n
> SCSI_DMA_BUF_SIZE
/ 512)
208 n
= SCSI_DMA_BUF_SIZE
/ 512;
210 r
->buf_len
= n
* 512;
211 r
->aiocb
= bdrv_aio_read(s
->bdrv
, r
->sector
, r
->dma_buf
, n
,
212 scsi_read_complete
, r
);
213 if (r
->aiocb
== NULL
)
214 scsi_command_complete(r
, STATUS_CHECK_CONDITION
, SENSE_HARDWARE_ERROR
);
216 r
->sector_count
-= n
;
219 static int scsi_handle_write_error(SCSIRequest
*r
, int error
)
221 BlockInterfaceErrorAction action
= drive_get_onerror(r
->dev
->bdrv
);
223 if (action
== BLOCK_ERR_IGNORE
)
226 if ((error
== ENOSPC
&& action
== BLOCK_ERR_STOP_ENOSPC
)
227 || action
== BLOCK_ERR_STOP_ANY
) {
228 r
->status
|= SCSI_REQ_STATUS_RETRY
;
231 scsi_command_complete(r
, STATUS_CHECK_CONDITION
,
232 SENSE_HARDWARE_ERROR
);
238 static void scsi_write_complete(void * opaque
, int ret
)
240 SCSIRequest
*r
= (SCSIRequest
*)opaque
;
241 SCSIDeviceState
*s
= r
->dev
;
248 if (scsi_handle_write_error(r
, -ret
))
252 n
= r
->buf_len
/ 512;
254 r
->sector_count
-= n
;
255 if (r
->sector_count
== 0) {
256 scsi_command_complete(r
, STATUS_GOOD
, SENSE_NO_SENSE
);
258 len
= r
->sector_count
* 512;
259 if (len
> SCSI_DMA_BUF_SIZE
) {
260 len
= SCSI_DMA_BUF_SIZE
;
263 DPRINTF("Write complete tag=0x%x more=%d\n", r
->tag
, len
);
264 s
->completion(s
->opaque
, SCSI_REASON_DATA
, r
->tag
, len
);
268 static void scsi_write_request(SCSIRequest
*r
)
270 SCSIDeviceState
*s
= r
->dev
;
273 n
= r
->buf_len
/ 512;
275 r
->aiocb
= bdrv_aio_write(s
->bdrv
, r
->sector
, r
->dma_buf
, n
,
276 scsi_write_complete
, r
);
277 if (r
->aiocb
== NULL
)
278 scsi_command_complete(r
, STATUS_CHECK_CONDITION
,
279 SENSE_HARDWARE_ERROR
);
281 /* Invoke completion routine to fetch data from host. */
282 scsi_write_complete(r
, 0);
286 /* Write data to a scsi device. Returns nonzero on failure.
287 The transfer may complete asynchronously. */
288 static int scsi_write_data(SCSIDevice
*d
, uint32_t tag
)
290 SCSIDeviceState
*s
= d
->state
;
293 DPRINTF("Write data tag=0x%x\n", tag
);
294 r
= scsi_find_request(s
, tag
);
296 BADF("Bad write tag 0x%x\n", tag
);
297 scsi_command_complete(r
, STATUS_CHECK_CONDITION
, SENSE_HARDWARE_ERROR
);
302 BADF("Data transfer already in progress\n");
304 scsi_write_request(r
);
309 static void scsi_dma_restart_cb(void *opaque
, int running
, int reason
)
311 SCSIDeviceState
*s
= opaque
;
312 SCSIRequest
*r
= s
->requests
;
317 if (r
->status
& SCSI_REQ_STATUS_RETRY
) {
318 r
->status
&= ~SCSI_REQ_STATUS_RETRY
;
319 scsi_write_request(r
);
325 /* Return a pointer to the data buffer. */
326 static uint8_t *scsi_get_buf(SCSIDevice
*d
, uint32_t tag
)
328 SCSIDeviceState
*s
= d
->state
;
331 r
= scsi_find_request(s
, tag
);
333 BADF("Bad buffer tag 0x%x\n", tag
);
339 /* Execute a scsi command. Returns the length of the data expected by the
340 command. This will be Positive for data transfers from the device
341 (eg. disk reads), negative for transfers to the device (eg. disk writes),
342 and zero if the command does not transfer any data. */
344 static int32_t scsi_send_command(SCSIDevice
*d
, uint32_t tag
,
345 uint8_t *buf
, int lun
)
347 SCSIDeviceState
*s
= d
->state
;
358 r
= scsi_find_request(s
, tag
);
360 BADF("Tag 0x%x already in use\n", tag
);
361 scsi_cancel_io(d
, tag
);
363 /* ??? Tags are not unique for different luns. We only implement a
364 single lun, so this should not matter. */
365 r
= scsi_new_request(s
, tag
);
368 DPRINTF("Command: lun=%d tag=0x%x data=0x%02x", lun
, tag
, buf
[0]);
369 switch (command
>> 5) {
371 lba
= buf
[3] | (buf
[2] << 8) | ((buf
[1] & 0x1f) << 16);
377 lba
= buf
[5] | (buf
[4] << 8) | (buf
[3] << 16) | (buf
[2] << 24);
378 len
= buf
[8] | (buf
[7] << 8);
382 lba
= buf
[5] | (buf
[4] << 8) | (buf
[3] << 16) | (buf
[2] << 24);
383 len
= buf
[13] | (buf
[12] << 8) | (buf
[11] << 16) | (buf
[10] << 24);
387 lba
= buf
[5] | (buf
[4] << 8) | (buf
[3] << 16) | (buf
[2] << 24);
388 len
= buf
[9] | (buf
[8] << 8) | (buf
[7] << 16) | (buf
[6] << 24);
392 BADF("Unsupported command length, command %x\n", command
);
398 for (i
= 1; i
< cmdlen
; i
++) {
399 printf(" 0x%02x", buf
[i
]);
404 if (lun
|| buf
[1] >> 5) {
405 /* Only LUN 0 supported. */
406 DPRINTF("Unimplemented LUN %d\n", lun
? lun
: buf
[1] >> 5);
407 if (command
!= 0x03 && command
!= 0x12) /* REQUEST SENSE and INQUIRY */
412 DPRINTF("Test Unit Ready\n");
415 DPRINTF("Request Sense (len %d)\n", len
);
418 memset(outbuf
, 0, 4);
421 outbuf
[2] = s
->sense
;
425 DPRINTF("Inquiry (len %d)\n", len
);
427 /* Command support data - optional, not implemented */
428 BADF("optional INQUIRY command support request not implemented\n");
431 else if (buf
[1] & 0x1) {
432 /* Vital product data */
433 uint8_t page_code
= buf
[2];
435 BADF("Error: Inquiry (EVPD[%02X]) buffer size %d is "
436 "less than 4\n", page_code
, len
);
443 /* Supported page codes, mandatory */
444 DPRINTF("Inquiry EVPD[Supported pages] "
445 "buffer size %d\n", len
);
449 if (bdrv_get_type_hint(s
->bdrv
) == BDRV_TYPE_CDROM
) {
450 outbuf
[r
->buf_len
++] = 5;
452 outbuf
[r
->buf_len
++] = 0;
455 outbuf
[r
->buf_len
++] = 0x00; // this page
456 outbuf
[r
->buf_len
++] = 0x00;
457 outbuf
[r
->buf_len
++] = 3; // number of pages
458 outbuf
[r
->buf_len
++] = 0x00; // list of supported pages (this page)
459 outbuf
[r
->buf_len
++] = 0x80; // unit serial number
460 outbuf
[r
->buf_len
++] = 0x83; // device identification
467 /* Device serial number, optional */
469 BADF("Error: EVPD[Serial number] Inquiry buffer "
470 "size %d too small, %d needed\n", len
, 4);
474 DPRINTF("Inquiry EVPD[Serial number] buffer size %d\n", len
);
475 l
= MIN(len
, strlen(s
->drive_serial_str
));
479 /* Supported page codes */
480 if (bdrv_get_type_hint(s
->bdrv
) == BDRV_TYPE_CDROM
) {
481 outbuf
[r
->buf_len
++] = 5;
483 outbuf
[r
->buf_len
++] = 0;
486 outbuf
[r
->buf_len
++] = 0x80; // this page
487 outbuf
[r
->buf_len
++] = 0x00;
488 outbuf
[r
->buf_len
++] = l
;
489 memcpy(&outbuf
[r
->buf_len
], s
->drive_serial_str
, l
);
496 /* Device identification page, mandatory */
497 int max_len
= 255 - 8;
498 int id_len
= strlen(bdrv_get_device_name(s
->bdrv
));
499 if (id_len
> max_len
)
502 DPRINTF("Inquiry EVPD[Device identification] "
503 "buffer size %d\n", len
);
505 if (bdrv_get_type_hint(s
->bdrv
) == BDRV_TYPE_CDROM
) {
506 outbuf
[r
->buf_len
++] = 5;
508 outbuf
[r
->buf_len
++] = 0;
511 outbuf
[r
->buf_len
++] = 0x83; // this page
512 outbuf
[r
->buf_len
++] = 0x00;
513 outbuf
[r
->buf_len
++] = 3 + id_len
;
515 outbuf
[r
->buf_len
++] = 0x2; // ASCII
516 outbuf
[r
->buf_len
++] = 0; // not officially assigned
517 outbuf
[r
->buf_len
++] = 0; // reserved
518 outbuf
[r
->buf_len
++] = id_len
; // length of data following
520 memcpy(&outbuf
[r
->buf_len
],
521 bdrv_get_device_name(s
->bdrv
), id_len
);
522 r
->buf_len
+= id_len
;
526 BADF("Error: unsupported Inquiry (EVPD[%02X]) "
527 "buffer size %d\n", page_code
, len
);
534 /* Standard INQUIRY data */
536 BADF("Error: Inquiry (STANDARD) page or code "
537 "is non-zero [%02X]\n", buf
[2]);
543 BADF("Error: Inquiry (STANDARD) buffer size %d "
544 "is less than 5\n", len
);
549 BADF("Error: Inquiry (STANDARD) buffer size %d "
550 "is less than 36 (TODO: only 5 required)\n", len
);
554 if(len
> SCSI_MAX_INQUIRY_LEN
)
555 len
= SCSI_MAX_INQUIRY_LEN
;
557 memset(outbuf
, 0, len
);
559 if (lun
|| buf
[1] >> 5) {
560 outbuf
[0] = 0x7f; /* LUN not supported */
561 } else if (bdrv_get_type_hint(s
->bdrv
) == BDRV_TYPE_CDROM
) {
564 memcpy(&outbuf
[16], "QEMU CD-ROM ", 16);
567 memcpy(&outbuf
[16], "QEMU HARDDISK ", 16);
569 memcpy(&outbuf
[8], "QEMU ", 8);
570 memcpy(&outbuf
[32], QEMU_VERSION
, 4);
571 /* Identify device as SCSI-3 rev 1.
572 Some later commands are also implemented. */
574 outbuf
[3] = 2; /* Format 2 */
575 outbuf
[4] = len
- 5; /* Additional Length = (Len - 1) - 4 */
576 /* Sync data transfer and TCQ. */
577 outbuf
[7] = 0x10 | (s
->tcq
? 0x02 : 0);
581 DPRINTF("Reserve(6)\n");
586 DPRINTF("Release(6)\n");
596 page
= buf
[2] & 0x3f;
597 DPRINTF("Mode Sense (page %d, len %d)\n", page
, len
);
600 outbuf
[1] = 0; /* Default media type. */
601 outbuf
[3] = 0; /* Block descriptor length. */
602 if (bdrv_get_type_hint(s
->bdrv
) == BDRV_TYPE_CDROM
) {
603 outbuf
[2] = 0x80; /* Readonly. */
607 int cylinders
, heads
, secs
;
609 /* Rigid disk device geometry page. */
612 /* if a geometry hint is available, use it */
613 bdrv_get_geometry_hint(s
->bdrv
, &cylinders
, &heads
, &secs
);
614 p
[2] = (cylinders
>> 16) & 0xff;
615 p
[3] = (cylinders
>> 8) & 0xff;
616 p
[4] = cylinders
& 0xff;
618 /* Write precomp start cylinder, disabled */
619 p
[6] = (cylinders
>> 16) & 0xff;
620 p
[7] = (cylinders
>> 8) & 0xff;
621 p
[8] = cylinders
& 0xff;
622 /* Reduced current start cylinder, disabled */
623 p
[9] = (cylinders
>> 16) & 0xff;
624 p
[10] = (cylinders
>> 8) & 0xff;
625 p
[11] = cylinders
& 0xff;
626 /* Device step rate [ns], 200ns */
629 /* Landing zone cylinder */
633 /* Medium rotation rate [rpm], 5400 rpm */
634 p
[20] = (5400 >> 8) & 0xff;
637 } else if (page
== 5) {
638 int cylinders
, heads
, secs
;
640 /* Flexible disk device geometry page. */
643 /* Transfer rate [kbit/s], 5Mbit/s */
646 /* if a geometry hint is available, use it */
647 bdrv_get_geometry_hint(s
->bdrv
, &cylinders
, &heads
, &secs
);
650 p
[6] = s
->cluster_size
* 2;
651 p
[8] = (cylinders
>> 8) & 0xff;
652 p
[9] = cylinders
& 0xff;
653 /* Write precomp start cylinder, disabled */
654 p
[10] = (cylinders
>> 8) & 0xff;
655 p
[11] = cylinders
& 0xff;
656 /* Reduced current start cylinder, disabled */
657 p
[12] = (cylinders
>> 8) & 0xff;
658 p
[13] = cylinders
& 0xff;
659 /* Device step rate [100us], 100us */
662 /* Device step pulse width [us], 1us */
664 /* Device head settle delay [100us], 100us */
667 /* Motor on delay [0.1s], 0.1s */
669 /* Motor off delay [0.1s], 0.1s */
671 /* Medium rotation rate [rpm], 5400 rpm */
672 p
[28] = (5400 >> 8) & 0xff;
675 } else if ((page
== 8 || page
== 0x3f)) {
683 if ((page
== 0x3f || page
== 0x2a)
684 && (bdrv_get_type_hint(s
->bdrv
) == BDRV_TYPE_CDROM
)) {
685 /* CD Capabilities and Mechanical Status page. */
688 p
[2] = 3; // CD-R & CD-RW read
689 p
[3] = 0; // Writing not supported
690 p
[4] = 0x7f; /* Audio, composite, digital out,
691 mode 2 form 1&2, multi session */
692 p
[5] = 0xff; /* CD DA, DA accurate, RW supported,
693 RW corrected, C2 errors, ISRC,
695 p
[6] = 0x2d | (bdrv_is_locked(s
->bdrv
)? 2 : 0);
696 /* Locking supported, jumper present, eject, tray */
697 p
[7] = 0; /* no volume & mute control, no
699 p
[8] = (50 * 176) >> 8; // 50x read speed
700 p
[9] = (50 * 176) & 0xff;
701 p
[10] = 0 >> 8; // No volume
703 p
[12] = 2048 >> 8; // 2M buffer
705 p
[14] = (16 * 176) >> 8; // 16x read speed current
706 p
[15] = (16 * 176) & 0xff;
707 p
[18] = (16 * 176) >> 8; // 16x write speed
708 p
[19] = (16 * 176) & 0xff;
709 p
[20] = (16 * 176) >> 8; // 16x write speed current
710 p
[21] = (16 * 176) & 0xff;
713 r
->buf_len
= p
- outbuf
;
714 outbuf
[0] = r
->buf_len
- 4;
715 if (r
->buf_len
> len
)
720 DPRINTF("Start Stop Unit\n");
723 DPRINTF("Prevent Allow Medium Removal (prevent = %d)\n", buf
[4] & 3);
724 bdrv_set_locked(s
->bdrv
, buf
[4] & 1);
727 DPRINTF("Read Capacity\n");
728 /* The normal LEN field for this command is zero. */
729 memset(outbuf
, 0, 8);
730 bdrv_get_geometry(s
->bdrv
, &nb_sectors
);
731 /* Returned value is the address of the last sector. */
734 /* Clip to 2TB, instead of returning capacity modulo 2TB. */
735 if (nb_sectors
> UINT32_MAX
)
736 nb_sectors
= UINT32_MAX
;
737 outbuf
[0] = (nb_sectors
>> 24) & 0xff;
738 outbuf
[1] = (nb_sectors
>> 16) & 0xff;
739 outbuf
[2] = (nb_sectors
>> 8) & 0xff;
740 outbuf
[3] = nb_sectors
& 0xff;
743 outbuf
[6] = s
->cluster_size
* 2;
747 scsi_command_complete(r
, STATUS_CHECK_CONDITION
, SENSE_NOT_READY
);
753 DPRINTF("Read (sector %d, count %d)\n", lba
, len
);
754 r
->sector
= lba
* s
->cluster_size
;
755 r
->sector_count
= len
* s
->cluster_size
;
759 DPRINTF("Write (sector %d, count %d)\n", lba
, len
);
760 r
->sector
= lba
* s
->cluster_size
;
761 r
->sector_count
= len
* s
->cluster_size
;
765 DPRINTF("Synchronise cache (sector %d, count %d)\n", lba
, len
);
770 int start_track
, format
, msf
, toclen
;
773 format
= buf
[2] & 0xf;
774 start_track
= buf
[6];
775 bdrv_get_geometry(s
->bdrv
, &nb_sectors
);
776 DPRINTF("Read TOC (track %d format %d msf %d)\n", start_track
, format
, msf
>> 1);
779 toclen
= cdrom_read_toc(nb_sectors
, outbuf
, msf
, start_track
);
782 /* multi session : only a single session defined */
784 memset(outbuf
, 0, 12);
790 toclen
= cdrom_read_toc_raw(nb_sectors
, outbuf
, msf
, start_track
);
802 DPRINTF("Read TOC error\n");
806 DPRINTF("Get Configuration (rt %d, maxlen %d)\n", buf
[1] & 3, len
);
807 memset(outbuf
, 0, 8);
808 /* ??? This should probably return much more information. For now
809 just return the basic header indicating the CD-ROM profile. */
810 outbuf
[7] = 8; // CD-ROM
814 DPRINTF("Reserve(10)\n");
819 DPRINTF("Release(10)\n");
824 DPRINTF("Report LUNs (len %d)\n", len
);
827 memset(outbuf
, 0, 16);
832 DPRINTF("Verify (sector %d, count %d)\n", lba
, len
);
835 DPRINTF("Unknown SCSI command (%2.2x)\n", buf
[0]);
837 scsi_command_complete(r
, STATUS_CHECK_CONDITION
, SENSE_ILLEGAL_REQUEST
);
840 if (r
->sector_count
== 0 && r
->buf_len
== 0) {
841 scsi_command_complete(r
, STATUS_GOOD
, SENSE_NO_SENSE
);
843 len
= r
->sector_count
* 512 + r
->buf_len
;
847 if (!r
->sector_count
)
848 r
->sector_count
= -1;
853 static void scsi_destroy(SCSIDevice
*d
)
859 SCSIDevice
*scsi_disk_init(BlockDriverState
*bdrv
, int tcq
,
860 scsi_completionfn completion
, void *opaque
)
865 s
= (SCSIDeviceState
*)qemu_mallocz(sizeof(SCSIDeviceState
));
868 s
->completion
= completion
;
870 if (bdrv_get_type_hint(s
->bdrv
) == BDRV_TYPE_CDROM
) {
875 strncpy(s
->drive_serial_str
, drive_get_serial(s
->bdrv
),
876 sizeof(s
->drive_serial_str
));
877 if (strlen(s
->drive_serial_str
) == 0)
878 pstrcpy(s
->drive_serial_str
, sizeof(s
->drive_serial_str
), "0");
879 qemu_add_vm_change_state_handler(scsi_dma_restart_cb
, s
);
880 d
= (SCSIDevice
*)qemu_mallocz(sizeof(SCSIDevice
));
882 d
->destroy
= scsi_destroy
;
883 d
->send_command
= scsi_send_command
;
884 d
->read_data
= scsi_read_data
;
885 d
->write_data
= scsi_write_data
;
886 d
->cancel_io
= scsi_cancel_io
;
887 d
->get_buf
= scsi_get_buf
;