8 #define MAX_SCSI_DEVS 255
10 #define SCSI_CMD_BUF_SIZE 16
12 typedef struct SCSIBus SCSIBus
;
13 typedef struct SCSIBusOps SCSIBusOps
;
14 typedef struct SCSIDevice SCSIDevice
;
15 typedef struct SCSIDeviceInfo SCSIDeviceInfo
;
16 typedef struct SCSIRequest SCSIRequest
;
19 SCSI_XFER_NONE
, /* TEST_UNIT_READY, ... */
20 SCSI_XFER_FROM_DEV
, /* READ, INQUIRY, MODE_SENSE, ... */
21 SCSI_XFER_TO_DEV
, /* WRITE, MODE_SELECT, ... */
24 typedef struct SCSISense
{
38 uint8_t buf
[SCSI_CMD_BUF_SIZE
];
42 enum SCSIXferMode mode
;
44 BlockDriverAIOCB
*aiocb
;
47 QTAILQ_ENTRY(SCSIRequest
) next
;
56 QTAILQ_HEAD(, SCSIRequest
) requests
;
62 int cdrom_read_toc(int nb_sectors
, uint8_t *buf
, int msf
, int start_track
);
63 int cdrom_read_toc_raw(int nb_sectors
, uint8_t *buf
, int msf
, int session_num
);
66 typedef int (*scsi_qdev_initfn
)(SCSIDevice
*dev
);
67 struct SCSIDeviceInfo
{
69 scsi_qdev_initfn init
;
70 void (*destroy
)(SCSIDevice
*s
);
71 SCSIRequest
*(*alloc_req
)(SCSIDevice
*s
, uint32_t tag
, uint32_t lun
,
73 void (*free_req
)(SCSIRequest
*req
);
74 int32_t (*send_command
)(SCSIRequest
*req
, uint8_t *buf
);
75 void (*read_data
)(SCSIRequest
*req
);
76 void (*write_data
)(SCSIRequest
*req
);
77 void (*cancel_io
)(SCSIRequest
*req
);
78 uint8_t *(*get_buf
)(SCSIRequest
*req
);
79 int (*get_sense
)(SCSIRequest
*req
, uint8_t *buf
, int len
);
83 void (*transfer_data
)(SCSIRequest
*req
, uint32_t arg
);
84 void (*complete
)(SCSIRequest
*req
, uint32_t arg
);
85 void (*cancel
)(SCSIRequest
*req
);
93 const SCSIBusOps
*ops
;
95 SCSIDevice
*devs
[MAX_SCSI_DEVS
];
98 void scsi_bus_new(SCSIBus
*bus
, DeviceState
*host
, int tcq
, int ndev
,
99 const SCSIBusOps
*ops
);
100 void scsi_qdev_register(SCSIDeviceInfo
*info
);
102 static inline SCSIBus
*scsi_bus_from_device(SCSIDevice
*d
)
104 return DO_UPCAST(SCSIBus
, qbus
, d
->qdev
.parent_bus
);
107 SCSIDevice
*scsi_bus_legacy_add_drive(SCSIBus
*bus
, BlockDriverState
*bdrv
,
108 int unit
, bool removable
);
109 int scsi_bus_legacy_handle_cmdline(SCSIBus
*bus
);
112 * Predefined sense codes
115 /* No sense data available */
116 extern const struct SCSISense sense_code_NO_SENSE
;
117 /* LUN not ready, Manual intervention required */
118 extern const struct SCSISense sense_code_LUN_NOT_READY
;
119 /* LUN not ready, Medium not present */
120 extern const struct SCSISense sense_code_NO_MEDIUM
;
121 /* Hardware error, internal target failure */
122 extern const struct SCSISense sense_code_TARGET_FAILURE
;
123 /* Illegal request, invalid command operation code */
124 extern const struct SCSISense sense_code_INVALID_OPCODE
;
125 /* Illegal request, LBA out of range */
126 extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE
;
127 /* Illegal request, Invalid field in CDB */
128 extern const struct SCSISense sense_code_INVALID_FIELD
;
129 /* Illegal request, LUN not supported */
130 extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED
;
131 /* Command aborted, I/O process terminated */
132 extern const struct SCSISense sense_code_IO_ERROR
;
133 /* Command aborted, I_T Nexus loss occurred */
134 extern const struct SCSISense sense_code_I_T_NEXUS_LOSS
;
135 /* Command aborted, Logical Unit failure */
136 extern const struct SCSISense sense_code_LUN_FAILURE
;
138 #define SENSE_CODE(x) sense_code_ ## x
140 int scsi_build_sense(SCSISense sense
, uint8_t *buf
, int len
, int fixed
);
141 int scsi_sense_valid(SCSISense sense
);
143 SCSIRequest
*scsi_req_alloc(size_t size
, SCSIDevice
*d
, uint32_t tag
,
144 uint32_t lun
, void *hba_private
);
145 SCSIRequest
*scsi_req_new(SCSIDevice
*d
, uint32_t tag
, uint32_t lun
,
147 int32_t scsi_req_enqueue(SCSIRequest
*req
, uint8_t *buf
);
148 void scsi_req_free(SCSIRequest
*req
);
149 SCSIRequest
*scsi_req_ref(SCSIRequest
*req
);
150 void scsi_req_unref(SCSIRequest
*req
);
152 int scsi_req_parse(SCSIRequest
*req
, uint8_t *buf
);
153 void scsi_req_print(SCSIRequest
*req
);
154 void scsi_req_continue(SCSIRequest
*req
);
155 void scsi_req_data(SCSIRequest
*req
, int len
);
156 void scsi_req_complete(SCSIRequest
*req
);
157 uint8_t *scsi_req_get_buf(SCSIRequest
*req
);
158 int scsi_req_get_sense(SCSIRequest
*req
, uint8_t *buf
, int len
);
159 void scsi_req_abort(SCSIRequest
*req
, int status
);
160 void scsi_req_cancel(SCSIRequest
*req
);
161 void scsi_device_purge_requests(SCSIDevice
*sdev
);