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