xref: /openbmc/qemu/include/hw/usb/msd.h (revision 2d708164)
1 /*
2  * USB Mass Storage Device emulation
3  *
4  * Copyright (c) 2006 CodeSourcery.
5  * Written by Paul Brook
6  *
7  * This code is licensed under the LGPL.
8  */
9 
10 #include "hw/usb.h"
11 #include "hw/scsi/scsi.h"
12 
13 enum USBMSDMode {
14     USB_MSDM_CBW, /* Command Block.  */
15     USB_MSDM_DATAOUT, /* Transfer data to device.  */
16     USB_MSDM_DATAIN, /* Transfer data from device.  */
17     USB_MSDM_CSW /* Command Status.  */
18 };
19 
20 struct QEMU_PACKED usb_msd_csw {
21     uint32_t sig;
22     uint32_t tag;
23     uint32_t residue;
24     uint8_t status;
25 };
26 
27 struct MSDState {
28     USBDevice dev;
29     enum USBMSDMode mode;
30     uint32_t scsi_off;
31     uint32_t scsi_len;
32     uint32_t data_len;
33     struct usb_msd_csw csw;
34     SCSIRequest *req;
35     SCSIBus bus;
36     /* For async completion.  */
37     USBPacket *packet;
38     /* usb-storage only */
39     BlockConf conf;
40     bool removable;
41     bool commandlog;
42     SCSIDevice *scsi_dev;
43     bool needs_reset;
44 };
45 
46 typedef struct MSDState MSDState;
47 #define TYPE_USB_STORAGE "usb-storage-dev"
48 DECLARE_INSTANCE_CHECKER(MSDState, USB_STORAGE_DEV,
49                          TYPE_USB_STORAGE)
50 
51 void usb_msd_transfer_data(SCSIRequest *req, uint32_t len);
52 void usb_msd_command_complete(SCSIRequest *req, size_t resid);
53 void usb_msd_request_cancelled(SCSIRequest *req);
54 void *usb_msd_load_request(QEMUFile *f, SCSIRequest *req);
55 void usb_msd_handle_reset(USBDevice *dev);
56