2009-11-26 17:33:47 +03:00
|
|
|
#ifndef QEMU_HW_SCSI_H
|
|
|
|
#define QEMU_HW_SCSI_H
|
2009-10-30 11:54:00 +03:00
|
|
|
|
|
|
|
#include "qdev.h"
|
2009-11-26 17:33:48 +03:00
|
|
|
#include "block.h"
|
2009-10-30 11:54:00 +03:00
|
|
|
|
2011-01-28 13:21:40 +03:00
|
|
|
#define MAX_SCSI_DEVS 255
|
|
|
|
|
2009-11-26 17:33:51 +03:00
|
|
|
#define SCSI_CMD_BUF_SIZE 16
|
|
|
|
|
2009-10-30 11:54:00 +03:00
|
|
|
typedef struct SCSIBus SCSIBus;
|
2011-04-18 19:11:14 +04:00
|
|
|
typedef struct SCSIBusOps SCSIBusOps;
|
2011-08-03 12:49:11 +04:00
|
|
|
typedef struct SCSICommand SCSICommand;
|
2009-10-30 11:54:00 +03:00
|
|
|
typedef struct SCSIDevice SCSIDevice;
|
|
|
|
typedef struct SCSIDeviceInfo SCSIDeviceInfo;
|
2011-04-18 14:35:39 +04:00
|
|
|
typedef struct SCSIRequest SCSIRequest;
|
2011-08-03 12:49:08 +04:00
|
|
|
typedef struct SCSIReqOps SCSIReqOps;
|
2009-10-30 11:54:00 +03:00
|
|
|
|
2009-11-26 17:33:57 +03:00
|
|
|
enum SCSIXferMode {
|
|
|
|
SCSI_XFER_NONE, /* TEST_UNIT_READY, ... */
|
|
|
|
SCSI_XFER_FROM_DEV, /* READ, INQUIRY, MODE_SENSE, ... */
|
|
|
|
SCSI_XFER_TO_DEV, /* WRITE, MODE_SELECT, ... */
|
|
|
|
};
|
|
|
|
|
2011-04-18 14:53:14 +04:00
|
|
|
typedef struct SCSISense {
|
|
|
|
uint8_t key;
|
|
|
|
uint8_t asc;
|
|
|
|
uint8_t ascq;
|
|
|
|
} SCSISense;
|
|
|
|
|
2011-08-03 12:49:07 +04:00
|
|
|
#define SCSI_SENSE_BUF_SIZE 96
|
|
|
|
|
2011-08-03 12:49:11 +04:00
|
|
|
struct SCSICommand {
|
|
|
|
uint8_t buf[SCSI_CMD_BUF_SIZE];
|
|
|
|
int len;
|
|
|
|
size_t xfer;
|
|
|
|
uint64_t lba;
|
|
|
|
enum SCSIXferMode mode;
|
|
|
|
};
|
|
|
|
|
2011-04-18 14:35:39 +04:00
|
|
|
struct SCSIRequest {
|
2009-11-26 17:33:48 +03:00
|
|
|
SCSIBus *bus;
|
|
|
|
SCSIDevice *dev;
|
2011-08-03 12:49:08 +04:00
|
|
|
SCSIReqOps *ops;
|
2011-04-18 18:01:56 +04:00
|
|
|
uint32_t refcount;
|
2009-11-26 17:33:48 +03:00
|
|
|
uint32_t tag;
|
2009-11-26 17:33:50 +03:00
|
|
|
uint32_t lun;
|
2009-11-26 17:34:00 +03:00
|
|
|
uint32_t status;
|
2011-08-03 12:49:11 +04:00
|
|
|
SCSICommand cmd;
|
2009-11-26 17:33:48 +03:00
|
|
|
BlockDriverAIOCB *aiocb;
|
2011-08-03 12:49:07 +04:00
|
|
|
uint8_t sense[SCSI_SENSE_BUF_SIZE];
|
|
|
|
uint32_t sense_len;
|
2010-07-13 16:13:45 +04:00
|
|
|
bool enqueued;
|
2011-07-11 17:02:24 +04:00
|
|
|
void *hba_private;
|
2009-11-26 17:33:49 +03:00
|
|
|
QTAILQ_ENTRY(SCSIRequest) next;
|
2011-04-18 14:35:39 +04:00
|
|
|
};
|
2009-11-26 17:33:48 +03:00
|
|
|
|
2009-10-30 11:54:00 +03:00
|
|
|
struct SCSIDevice
|
|
|
|
{
|
|
|
|
DeviceState qdev;
|
|
|
|
uint32_t id;
|
block: add topology qdev properties
Add three new qdev properties to export block topology information to
the guest. This is needed to get optimal I/O alignment for RAID arrays
or SSDs.
The options are:
- physical_block_size to specify the physical block size of the device,
this is going to increase from 512 bytes to 4096 kilobytes for many
modern storage devices
- min_io_size to specify the minimal I/O size without performance impact,
this is typically set to the RAID chunk size for arrays.
- opt_io_size to specify the optimal sustained I/O size, this is
typically the RAID stripe width for arrays.
I decided to not auto-probe these values from blkid which might easily
be possible as I don't know how to deal with these issues on migration.
Note that we specificly only set the physical_block_size, and not the
logial one which is the unit all I/O is described in. The reason for
that is that IDE does not support increasing the logical block size and
at last for now I want to stick to one meachnisms in queue and allow
for easy switching of transports for a given backing image which would
not be possible if scsi and virtio use real 4k sectors, while ide only
uses the physical block exponent.
To make this more common for the different block drivers introduce a
new BlockConf structure holding all common block properties and a
DEFINE_BLOCK_PROPERTIES macro to add them all together, mirroring
what is done for network drivers. Also switch over all block drivers
to use it, except for the floppy driver which has weird driveA/driveB
properties and probably won't require any advanced block options ever.
Example usage for a virtio device with 4k physical block size and
8k optimal I/O size:
-drive file=scratch.img,media=disk,cache=none,id=scratch \
-device virtio-blk-pci,drive=scratch,physical_block_size=4096,opt_io_size=8192
aliguori: updated patch to take into account BLOCK events
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-11 01:37:09 +03:00
|
|
|
BlockConf conf;
|
2009-10-30 11:54:00 +03:00
|
|
|
SCSIDeviceInfo *info;
|
2011-08-03 12:49:17 +04:00
|
|
|
SCSISense unit_attention;
|
2011-08-03 12:49:07 +04:00
|
|
|
uint8_t sense[SCSI_SENSE_BUF_SIZE];
|
|
|
|
uint32_t sense_len;
|
2009-11-26 17:33:49 +03:00
|
|
|
QTAILQ_HEAD(, SCSIRequest) requests;
|
2011-08-03 12:49:12 +04:00
|
|
|
uint32_t lun;
|
2009-11-26 17:33:52 +03:00
|
|
|
int blocksize;
|
2009-11-26 17:33:54 +03:00
|
|
|
int type;
|
2009-10-30 11:54:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/* cdrom.c */
|
|
|
|
int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
|
|
|
|
int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
|
|
|
|
|
|
|
|
/* scsi-bus.c */
|
2011-08-03 12:49:08 +04:00
|
|
|
struct SCSIReqOps {
|
|
|
|
size_t size;
|
2011-08-03 12:49:09 +04:00
|
|
|
void (*free_req)(SCSIRequest *req);
|
|
|
|
int32_t (*send_command)(SCSIRequest *req, uint8_t *buf);
|
|
|
|
void (*read_data)(SCSIRequest *req);
|
|
|
|
void (*write_data)(SCSIRequest *req);
|
|
|
|
void (*cancel_io)(SCSIRequest *req);
|
|
|
|
uint8_t *(*get_buf)(SCSIRequest *req);
|
2011-08-03 12:49:08 +04:00
|
|
|
};
|
|
|
|
|
2009-10-30 11:54:00 +03:00
|
|
|
typedef int (*scsi_qdev_initfn)(SCSIDevice *dev);
|
|
|
|
struct SCSIDeviceInfo {
|
|
|
|
DeviceInfo qdev;
|
|
|
|
scsi_qdev_initfn init;
|
|
|
|
void (*destroy)(SCSIDevice *s);
|
2011-07-11 17:02:24 +04:00
|
|
|
SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun,
|
|
|
|
void *hba_private);
|
2011-08-03 12:49:09 +04:00
|
|
|
SCSIReqOps reqops;
|
2009-10-30 11:54:00 +03:00
|
|
|
};
|
|
|
|
|
2011-04-18 19:11:14 +04:00
|
|
|
struct SCSIBusOps {
|
2011-04-22 14:27:30 +04:00
|
|
|
void (*transfer_data)(SCSIRequest *req, uint32_t arg);
|
|
|
|
void (*complete)(SCSIRequest *req, uint32_t arg);
|
2011-04-19 00:53:08 +04:00
|
|
|
void (*cancel)(SCSIRequest *req);
|
2011-04-18 19:11:14 +04:00
|
|
|
};
|
|
|
|
|
2009-10-30 11:54:00 +03:00
|
|
|
struct SCSIBus {
|
|
|
|
BusState qbus;
|
|
|
|
int busnr;
|
|
|
|
|
2011-08-03 12:49:17 +04:00
|
|
|
SCSISense unit_attention;
|
2009-10-30 11:54:00 +03:00
|
|
|
int tcq, ndev;
|
2011-04-18 19:11:14 +04:00
|
|
|
const SCSIBusOps *ops;
|
2009-10-30 11:54:00 +03:00
|
|
|
|
2010-11-24 14:15:56 +03:00
|
|
|
SCSIDevice *devs[MAX_SCSI_DEVS];
|
2009-10-30 11:54:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev,
|
2011-04-18 19:11:14 +04:00
|
|
|
const SCSIBusOps *ops);
|
2009-10-30 11:54:00 +03:00
|
|
|
void scsi_qdev_register(SCSIDeviceInfo *info);
|
|
|
|
|
|
|
|
static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
|
|
|
|
{
|
|
|
|
return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus);
|
|
|
|
}
|
|
|
|
|
2011-01-24 18:34:59 +03:00
|
|
|
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
|
|
|
|
int unit, bool removable);
|
2010-06-25 20:53:21 +04:00
|
|
|
int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
|
2009-10-30 11:54:00 +03:00
|
|
|
|
2011-04-18 14:53:14 +04:00
|
|
|
/*
|
|
|
|
* Predefined sense codes
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* No sense data available */
|
|
|
|
extern const struct SCSISense sense_code_NO_SENSE;
|
|
|
|
/* LUN not ready, Manual intervention required */
|
|
|
|
extern const struct SCSISense sense_code_LUN_NOT_READY;
|
|
|
|
/* LUN not ready, Medium not present */
|
|
|
|
extern const struct SCSISense sense_code_NO_MEDIUM;
|
2011-09-06 20:58:49 +04:00
|
|
|
/* LUN not ready, medium removal prevented */
|
|
|
|
extern const struct SCSISense sense_code_NOT_READY_REMOVAL_PREVENTED;
|
2011-04-18 14:53:14 +04:00
|
|
|
/* Hardware error, internal target failure */
|
|
|
|
extern const struct SCSISense sense_code_TARGET_FAILURE;
|
|
|
|
/* Illegal request, invalid command operation code */
|
|
|
|
extern const struct SCSISense sense_code_INVALID_OPCODE;
|
|
|
|
/* Illegal request, LBA out of range */
|
|
|
|
extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE;
|
|
|
|
/* Illegal request, Invalid field in CDB */
|
|
|
|
extern const struct SCSISense sense_code_INVALID_FIELD;
|
|
|
|
/* Illegal request, LUN not supported */
|
|
|
|
extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED;
|
2011-08-03 12:49:16 +04:00
|
|
|
/* Illegal request, Saving parameters not supported */
|
|
|
|
extern const struct SCSISense sense_code_SAVING_PARAMS_NOT_SUPPORTED;
|
|
|
|
/* Illegal request, Incompatible format */
|
|
|
|
extern const struct SCSISense sense_code_INCOMPATIBLE_FORMAT;
|
2011-09-06 20:58:49 +04:00
|
|
|
/* Illegal request, medium removal prevented */
|
|
|
|
extern const struct SCSISense sense_code_ILLEGAL_REQ_REMOVAL_PREVENTED;
|
2011-04-18 14:53:14 +04:00
|
|
|
/* Command aborted, I/O process terminated */
|
|
|
|
extern const struct SCSISense sense_code_IO_ERROR;
|
|
|
|
/* Command aborted, I_T Nexus loss occurred */
|
|
|
|
extern const struct SCSISense sense_code_I_T_NEXUS_LOSS;
|
|
|
|
/* Command aborted, Logical Unit failure */
|
|
|
|
extern const struct SCSISense sense_code_LUN_FAILURE;
|
2011-08-03 12:49:16 +04:00
|
|
|
/* Unit attention, Power on, reset or bus device reset occurred */
|
|
|
|
extern const struct SCSISense sense_code_RESET;
|
|
|
|
/* Unit attention, Medium may have changed*/
|
|
|
|
extern const struct SCSISense sense_code_MEDIUM_CHANGED;
|
|
|
|
/* Unit attention, Reported LUNs data has changed */
|
|
|
|
extern const struct SCSISense sense_code_REPORTED_LUNS_CHANGED;
|
|
|
|
/* Unit attention, Device internal reset */
|
|
|
|
extern const struct SCSISense sense_code_DEVICE_INTERNAL_RESET;
|
2011-04-18 14:53:14 +04:00
|
|
|
|
|
|
|
#define SENSE_CODE(x) sense_code_ ## x
|
|
|
|
|
|
|
|
int scsi_sense_valid(SCSISense sense);
|
|
|
|
|
2011-08-03 12:49:08 +04:00
|
|
|
SCSIRequest *scsi_req_alloc(SCSIReqOps *reqops, SCSIDevice *d, uint32_t tag,
|
2011-07-11 17:02:24 +04:00
|
|
|
uint32_t lun, void *hba_private);
|
|
|
|
SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun,
|
2011-08-03 12:49:10 +04:00
|
|
|
uint8_t *buf, void *hba_private);
|
|
|
|
int32_t scsi_req_enqueue(SCSIRequest *req);
|
2009-11-26 17:33:50 +03:00
|
|
|
void scsi_req_free(SCSIRequest *req);
|
2011-04-18 18:01:56 +04:00
|
|
|
SCSIRequest *scsi_req_ref(SCSIRequest *req);
|
|
|
|
void scsi_req_unref(SCSIRequest *req);
|
2009-11-26 17:33:58 +03:00
|
|
|
|
2011-08-03 12:49:07 +04:00
|
|
|
void scsi_req_build_sense(SCSIRequest *req, SCSISense sense);
|
2009-11-26 17:34:01 +03:00
|
|
|
void scsi_req_print(SCSIRequest *req);
|
2011-04-18 17:28:11 +04:00
|
|
|
void scsi_req_continue(SCSIRequest *req);
|
2011-04-18 16:59:13 +04:00
|
|
|
void scsi_req_data(SCSIRequest *req, int len);
|
2011-08-03 12:49:06 +04:00
|
|
|
void scsi_req_complete(SCSIRequest *req, int status);
|
2011-04-21 15:21:02 +04:00
|
|
|
uint8_t *scsi_req_get_buf(SCSIRequest *req);
|
2011-04-18 15:36:02 +04:00
|
|
|
int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len);
|
2011-04-18 19:14:51 +04:00
|
|
|
void scsi_req_abort(SCSIRequest *req, int status);
|
2011-04-19 00:53:08 +04:00
|
|
|
void scsi_req_cancel(SCSIRequest *req);
|
2011-08-03 12:49:18 +04:00
|
|
|
void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense);
|
2011-08-03 12:49:07 +04:00
|
|
|
int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed);
|
2009-11-26 17:33:50 +03:00
|
|
|
|
2009-10-30 11:54:00 +03:00
|
|
|
#endif
|