xref: /openbmc/qemu/pc-bios/s390-ccw/virtio-scsi.h (revision dc5bd18f)
1 /*
2  * Virtio-SCSI definitions for s390 machine loader for qemu
3  *
4  * Copyright 2015 IBM Corp.
5  * Author: Eugene "jno" Dvurechenski <jno@linux.vnet.ibm.com>
6  *
7  * This work is licensed under the terms of the GNU GPL, version 2 or (at
8  * your option) any later version. See the COPYING file in the top-level
9  * directory.
10  */
11 
12 #ifndef VIRTIO_SCSI_H
13 #define VIRTIO_SCSI_H
14 
15 #include "s390-ccw.h"
16 #include "virtio.h"
17 #include "scsi.h"
18 
19 #define VIRTIO_SCSI_CDB_SIZE   SCSI_DEFAULT_CDB_SIZE
20 #define VIRTIO_SCSI_SENSE_SIZE SCSI_DEFAULT_SENSE_SIZE
21 
22 #define VIRTIO_SCSI_MAX_SECTORS 2048
23 
24 /* command-specific response values */
25 #define VIRTIO_SCSI_S_OK                     0x00
26 #define VIRTIO_SCSI_S_BAD_TARGET             0x03
27 
28 #define QEMU_CDROM_SIGNATURE "QEMU CD-ROM     "
29 
30 enum virtio_scsi_vq_id {
31     VR_CONTROL  = 0,
32     VR_EVENT    = 1,
33     VR_REQUEST  = 2,
34 };
35 
36 struct VirtioScsiCmdReq {
37     ScsiLun lun;
38     uint64_t id;
39     uint8_t task_attr;   /* = 0 = VIRTIO_SCSI_S_SIMPLE */
40     uint8_t prio;
41     uint8_t crn;         /* = 0 */
42     uint8_t cdb[VIRTIO_SCSI_CDB_SIZE];
43 } __attribute__((packed));
44 typedef struct VirtioScsiCmdReq VirtioScsiCmdReq;
45 
46 struct VirtioScsiCmdResp {
47         uint32_t sense_len;
48         uint32_t residual;
49         uint16_t status_qualifier;
50         uint8_t status;      /* first check for .response    */
51         uint8_t response;    /* then for .status             */
52         uint8_t sense[VIRTIO_SCSI_SENSE_SIZE];
53 } __attribute__((packed));
54 typedef struct VirtioScsiCmdResp VirtioScsiCmdResp;
55 
56 static inline const char *virtio_scsi_response_msg(const VirtioScsiCmdResp *r)
57 {
58     static char err_msg[] = "VS RESP=XX";
59     uint8_t v = r->response;
60 
61     fill_hex_val(err_msg + 8, &v, 1);
62     return err_msg;
63 }
64 
65 static inline bool virtio_scsi_response_ok(const VirtioScsiCmdResp *r)
66 {
67         return r->response == VIRTIO_SCSI_S_OK && r->status == CDB_STATUS_GOOD;
68 }
69 
70 void virtio_scsi_setup(VDev *vdev);
71 int virtio_scsi_read_many(VDev *vdev,
72                           ulong sector, void *load_addr, int sec_num);
73 
74 #endif /* VIRTIO_SCSI_H */
75