usb: split packet result into actual_length + status
[qemu.git] / hw / usb / dev-uas.c
bloba21b2ba62788c2257e134f71ebec320c9247b5f2
1 /*
2 * UAS (USB Attached SCSI) emulation
4 * Copyright Red Hat, Inc. 2012
6 * Author: Gerd Hoffmann <kraxel@redhat.com>
8 * This work is licensed under the terms of the GNU GPL, version 2 or later.
9 * See the COPYING file in the top-level directory.
12 #include "qemu-common.h"
13 #include "qemu-option.h"
14 #include "qemu-config.h"
15 #include "trace.h"
17 #include "hw/usb.h"
18 #include "hw/usb/desc.h"
19 #include "hw/scsi.h"
20 #include "hw/scsi-defs.h"
22 /* --------------------------------------------------------------------- */
24 #define UAS_UI_COMMAND 0x01
25 #define UAS_UI_SENSE 0x03
26 #define UAS_UI_RESPONSE 0x04
27 #define UAS_UI_TASK_MGMT 0x05
28 #define UAS_UI_READ_READY 0x06
29 #define UAS_UI_WRITE_READY 0x07
31 #define UAS_RC_TMF_COMPLETE 0x00
32 #define UAS_RC_INVALID_INFO_UNIT 0x02
33 #define UAS_RC_TMF_NOT_SUPPORTED 0x04
34 #define UAS_RC_TMF_FAILED 0x05
35 #define UAS_RC_TMF_SUCCEEDED 0x08
36 #define UAS_RC_INCORRECT_LUN 0x09
37 #define UAS_RC_OVERLAPPED_TAG 0x0a
39 #define UAS_TMF_ABORT_TASK 0x01
40 #define UAS_TMF_ABORT_TASK_SET 0x02
41 #define UAS_TMF_CLEAR_TASK_SET 0x04
42 #define UAS_TMF_LOGICAL_UNIT_RESET 0x08
43 #define UAS_TMF_I_T_NEXUS_RESET 0x10
44 #define UAS_TMF_CLEAR_ACA 0x40
45 #define UAS_TMF_QUERY_TASK 0x80
46 #define UAS_TMF_QUERY_TASK_SET 0x81
47 #define UAS_TMF_QUERY_ASYNC_EVENT 0x82
49 #define UAS_PIPE_ID_COMMAND 0x01
50 #define UAS_PIPE_ID_STATUS 0x02
51 #define UAS_PIPE_ID_DATA_IN 0x03
52 #define UAS_PIPE_ID_DATA_OUT 0x04
54 typedef struct {
55 uint8_t id;
56 uint8_t reserved;
57 uint16_t tag;
58 } QEMU_PACKED uas_ui_header;
60 typedef struct {
61 uint8_t prio_taskattr; /* 6:3 priority, 2:0 task attribute */
62 uint8_t reserved_1;
63 uint8_t add_cdb_length; /* 7:2 additional adb length (dwords) */
64 uint8_t reserved_2;
65 uint64_t lun;
66 uint8_t cdb[16];
67 uint8_t add_cdb[];
68 } QEMU_PACKED uas_ui_command;
70 typedef struct {
71 uint16_t status_qualifier;
72 uint8_t status;
73 uint8_t reserved[7];
74 uint16_t sense_length;
75 uint8_t sense_data[18];
76 } QEMU_PACKED uas_ui_sense;
78 typedef struct {
79 uint16_t add_response_info;
80 uint8_t response_code;
81 } QEMU_PACKED uas_ui_response;
83 typedef struct {
84 uint8_t function;
85 uint8_t reserved;
86 uint16_t task_tag;
87 uint64_t lun;
88 } QEMU_PACKED uas_ui_task_mgmt;
90 typedef struct {
91 uas_ui_header hdr;
92 union {
93 uas_ui_command command;
94 uas_ui_sense sense;
95 uas_ui_task_mgmt task;
96 uas_ui_response response;
98 } QEMU_PACKED uas_ui;
100 /* --------------------------------------------------------------------- */
102 typedef struct UASDevice UASDevice;
103 typedef struct UASRequest UASRequest;
104 typedef struct UASStatus UASStatus;
106 struct UASDevice {
107 USBDevice dev;
108 SCSIBus bus;
109 UASRequest *datain;
110 UASRequest *dataout;
111 USBPacket *status;
112 QEMUBH *status_bh;
113 QTAILQ_HEAD(, UASStatus) results;
114 QTAILQ_HEAD(, UASRequest) requests;
117 struct UASRequest {
118 uint16_t tag;
119 uint64_t lun;
120 UASDevice *uas;
121 SCSIDevice *dev;
122 SCSIRequest *req;
123 USBPacket *data;
124 bool data_async;
125 bool active;
126 bool complete;
127 uint32_t buf_off;
128 uint32_t buf_size;
129 uint32_t data_off;
130 uint32_t data_size;
131 QTAILQ_ENTRY(UASRequest) next;
134 struct UASStatus {
135 uas_ui status;
136 uint32_t length;
137 QTAILQ_ENTRY(UASStatus) next;
140 /* --------------------------------------------------------------------- */
142 enum {
143 STR_MANUFACTURER = 1,
144 STR_PRODUCT,
145 STR_SERIALNUMBER,
146 STR_CONFIG_HIGH,
149 static const USBDescStrings desc_strings = {
150 [STR_MANUFACTURER] = "QEMU",
151 [STR_PRODUCT] = "USB Attached SCSI HBA",
152 [STR_SERIALNUMBER] = "27842",
153 [STR_CONFIG_HIGH] = "High speed config (usb 2.0)",
156 static const USBDescIface desc_iface_high = {
157 .bInterfaceNumber = 0,
158 .bNumEndpoints = 4,
159 .bInterfaceClass = USB_CLASS_MASS_STORAGE,
160 .bInterfaceSubClass = 0x06, /* SCSI */
161 .bInterfaceProtocol = 0x62, /* UAS */
162 .eps = (USBDescEndpoint[]) {
164 .bEndpointAddress = USB_DIR_OUT | UAS_PIPE_ID_COMMAND,
165 .bmAttributes = USB_ENDPOINT_XFER_BULK,
166 .wMaxPacketSize = 512,
167 .extra = (uint8_t[]) {
168 0x04, /* u8 bLength */
169 0x24, /* u8 bDescriptorType */
170 UAS_PIPE_ID_COMMAND,
171 0x00, /* u8 bReserved */
174 .bEndpointAddress = USB_DIR_IN | UAS_PIPE_ID_STATUS,
175 .bmAttributes = USB_ENDPOINT_XFER_BULK,
176 .wMaxPacketSize = 512,
177 .extra = (uint8_t[]) {
178 0x04, /* u8 bLength */
179 0x24, /* u8 bDescriptorType */
180 UAS_PIPE_ID_STATUS,
181 0x00, /* u8 bReserved */
184 .bEndpointAddress = USB_DIR_IN | UAS_PIPE_ID_DATA_IN,
185 .bmAttributes = USB_ENDPOINT_XFER_BULK,
186 .wMaxPacketSize = 512,
187 .extra = (uint8_t[]) {
188 0x04, /* u8 bLength */
189 0x24, /* u8 bDescriptorType */
190 UAS_PIPE_ID_DATA_IN,
191 0x00, /* u8 bReserved */
194 .bEndpointAddress = USB_DIR_OUT | UAS_PIPE_ID_DATA_OUT,
195 .bmAttributes = USB_ENDPOINT_XFER_BULK,
196 .wMaxPacketSize = 512,
197 .extra = (uint8_t[]) {
198 0x04, /* u8 bLength */
199 0x24, /* u8 bDescriptorType */
200 UAS_PIPE_ID_DATA_OUT,
201 0x00, /* u8 bReserved */
207 static const USBDescDevice desc_device_high = {
208 .bcdUSB = 0x0200,
209 .bMaxPacketSize0 = 64,
210 .bNumConfigurations = 1,
211 .confs = (USBDescConfig[]) {
213 .bNumInterfaces = 1,
214 .bConfigurationValue = 1,
215 .iConfiguration = STR_CONFIG_HIGH,
216 .bmAttributes = 0xc0,
217 .nif = 1,
218 .ifs = &desc_iface_high,
223 static const USBDesc desc = {
224 .id = {
225 .idVendor = 0x46f4, /* CRC16() of "QEMU" */
226 .idProduct = 0x0003,
227 .bcdDevice = 0,
228 .iManufacturer = STR_MANUFACTURER,
229 .iProduct = STR_PRODUCT,
230 .iSerialNumber = STR_SERIALNUMBER,
232 .high = &desc_device_high,
233 .str = desc_strings,
236 /* --------------------------------------------------------------------- */
238 static UASStatus *usb_uas_alloc_status(uint8_t id, uint16_t tag)
240 UASStatus *st = g_new0(UASStatus, 1);
242 st->status.hdr.id = id;
243 st->status.hdr.tag = cpu_to_be16(tag);
244 st->length = sizeof(uas_ui_header);
245 return st;
248 static void usb_uas_send_status_bh(void *opaque)
250 UASDevice *uas = opaque;
251 UASStatus *st = QTAILQ_FIRST(&uas->results);
252 USBPacket *p = uas->status;
254 assert(p != NULL);
255 assert(st != NULL);
257 uas->status = NULL;
258 usb_packet_copy(p, &st->status, st->length);
259 QTAILQ_REMOVE(&uas->results, st, next);
260 g_free(st);
262 p->status = USB_RET_SUCCESS; /* Clear previous ASYNC status */
263 usb_packet_complete(&uas->dev, p);
266 static void usb_uas_queue_status(UASDevice *uas, UASStatus *st, int length)
268 st->length += length;
269 QTAILQ_INSERT_TAIL(&uas->results, st, next);
270 if (uas->status) {
272 * Just schedule bh make sure any in-flight data transaction
273 * is finished before completing (sending) the status packet.
275 qemu_bh_schedule(uas->status_bh);
276 } else {
277 USBEndpoint *ep = usb_ep_get(&uas->dev, USB_TOKEN_IN,
278 UAS_PIPE_ID_STATUS);
279 usb_wakeup(ep);
283 static void usb_uas_queue_response(UASDevice *uas, uint16_t tag,
284 uint8_t code, uint16_t add_info)
286 UASStatus *st = usb_uas_alloc_status(UAS_UI_RESPONSE, tag);
288 trace_usb_uas_response(uas->dev.addr, tag, code);
289 st->status.response.response_code = code;
290 st->status.response.add_response_info = cpu_to_be16(add_info);
291 usb_uas_queue_status(uas, st, sizeof(uas_ui_response));
294 static void usb_uas_queue_sense(UASRequest *req, uint8_t status)
296 UASStatus *st = usb_uas_alloc_status(UAS_UI_SENSE, req->tag);
297 int len, slen = 0;
299 trace_usb_uas_sense(req->uas->dev.addr, req->tag, status);
300 st->status.sense.status = status;
301 st->status.sense.status_qualifier = cpu_to_be16(0);
302 if (status != GOOD) {
303 slen = scsi_req_get_sense(req->req, st->status.sense.sense_data,
304 sizeof(st->status.sense.sense_data));
305 st->status.sense.sense_length = cpu_to_be16(slen);
307 len = sizeof(uas_ui_sense) - sizeof(st->status.sense.sense_data) + slen;
308 usb_uas_queue_status(req->uas, st, len);
311 static void usb_uas_queue_read_ready(UASRequest *req)
313 UASStatus *st = usb_uas_alloc_status(UAS_UI_READ_READY, req->tag);
315 trace_usb_uas_read_ready(req->uas->dev.addr, req->tag);
316 usb_uas_queue_status(req->uas, st, 0);
319 static void usb_uas_queue_write_ready(UASRequest *req)
321 UASStatus *st = usb_uas_alloc_status(UAS_UI_WRITE_READY, req->tag);
323 trace_usb_uas_write_ready(req->uas->dev.addr, req->tag);
324 usb_uas_queue_status(req->uas, st, 0);
327 /* --------------------------------------------------------------------- */
329 static int usb_uas_get_lun(uint64_t lun64)
331 return (lun64 >> 48) & 0xff;
334 static SCSIDevice *usb_uas_get_dev(UASDevice *uas, uint64_t lun64)
336 if ((lun64 >> 56) != 0x00) {
337 return NULL;
339 return scsi_device_find(&uas->bus, 0, 0, usb_uas_get_lun(lun64));
342 static void usb_uas_complete_data_packet(UASRequest *req)
344 USBPacket *p;
346 if (!req->data_async) {
347 return;
349 p = req->data;
350 req->data = NULL;
351 req->data_async = false;
352 p->status = USB_RET_SUCCESS; /* Clear previous ASYNC status */
353 usb_packet_complete(&req->uas->dev, p);
356 static void usb_uas_copy_data(UASRequest *req)
358 uint32_t length;
360 length = MIN(req->buf_size - req->buf_off,
361 req->data->iov.size - req->data->actual_length);
362 trace_usb_uas_xfer_data(req->uas->dev.addr, req->tag, length,
363 req->data->actual_length, req->data->iov.size,
364 req->buf_off, req->buf_size);
365 usb_packet_copy(req->data, scsi_req_get_buf(req->req) + req->buf_off,
366 length);
367 req->buf_off += length;
368 req->data_off += length;
370 if (req->data->actual_length == req->data->iov.size) {
371 usb_uas_complete_data_packet(req);
373 if (req->buf_size && req->buf_off == req->buf_size) {
374 req->buf_off = 0;
375 req->buf_size = 0;
376 scsi_req_continue(req->req);
380 static void usb_uas_start_next_transfer(UASDevice *uas)
382 UASRequest *req;
384 QTAILQ_FOREACH(req, &uas->requests, next) {
385 if (req->active || req->complete) {
386 continue;
388 if (req->req->cmd.mode == SCSI_XFER_FROM_DEV && uas->datain == NULL) {
389 uas->datain = req;
390 usb_uas_queue_read_ready(req);
391 req->active = true;
392 return;
394 if (req->req->cmd.mode == SCSI_XFER_TO_DEV && uas->dataout == NULL) {
395 uas->dataout = req;
396 usb_uas_queue_write_ready(req);
397 req->active = true;
398 return;
403 static UASRequest *usb_uas_alloc_request(UASDevice *uas, uas_ui *ui)
405 UASRequest *req;
407 req = g_new0(UASRequest, 1);
408 req->uas = uas;
409 req->tag = be16_to_cpu(ui->hdr.tag);
410 req->lun = be64_to_cpu(ui->command.lun);
411 req->dev = usb_uas_get_dev(req->uas, req->lun);
412 return req;
415 static void usb_uas_scsi_free_request(SCSIBus *bus, void *priv)
417 UASRequest *req = priv;
418 UASDevice *uas = req->uas;
420 if (req == uas->datain) {
421 uas->datain = NULL;
423 if (req == uas->dataout) {
424 uas->dataout = NULL;
426 QTAILQ_REMOVE(&uas->requests, req, next);
427 g_free(req);
428 usb_uas_start_next_transfer(uas);
431 static UASRequest *usb_uas_find_request(UASDevice *uas, uint16_t tag)
433 UASRequest *req;
435 QTAILQ_FOREACH(req, &uas->requests, next) {
436 if (req->tag == tag) {
437 return req;
440 return NULL;
443 static void usb_uas_scsi_transfer_data(SCSIRequest *r, uint32_t len)
445 UASRequest *req = r->hba_private;
447 trace_usb_uas_scsi_data(req->uas->dev.addr, req->tag, len);
448 req->buf_off = 0;
449 req->buf_size = len;
450 if (req->data) {
451 usb_uas_copy_data(req);
452 } else {
453 usb_uas_start_next_transfer(req->uas);
457 static void usb_uas_scsi_command_complete(SCSIRequest *r,
458 uint32_t status, size_t resid)
460 UASRequest *req = r->hba_private;
462 trace_usb_uas_scsi_complete(req->uas->dev.addr, req->tag, status, resid);
463 req->complete = true;
464 if (req->data) {
465 usb_uas_complete_data_packet(req);
467 usb_uas_queue_sense(req, status);
468 scsi_req_unref(req->req);
471 static void usb_uas_scsi_request_cancelled(SCSIRequest *r)
473 UASRequest *req = r->hba_private;
475 /* FIXME: queue notification to status pipe? */
476 scsi_req_unref(req->req);
479 static const struct SCSIBusInfo usb_uas_scsi_info = {
480 .tcq = true,
481 .max_target = 0,
482 .max_lun = 255,
484 .transfer_data = usb_uas_scsi_transfer_data,
485 .complete = usb_uas_scsi_command_complete,
486 .cancel = usb_uas_scsi_request_cancelled,
487 .free_request = usb_uas_scsi_free_request,
490 /* --------------------------------------------------------------------- */
492 static void usb_uas_handle_reset(USBDevice *dev)
494 UASDevice *uas = DO_UPCAST(UASDevice, dev, dev);
495 UASRequest *req, *nreq;
496 UASStatus *st, *nst;
498 trace_usb_uas_reset(dev->addr);
499 QTAILQ_FOREACH_SAFE(req, &uas->requests, next, nreq) {
500 scsi_req_cancel(req->req);
502 QTAILQ_FOREACH_SAFE(st, &uas->results, next, nst) {
503 QTAILQ_REMOVE(&uas->results, st, next);
504 g_free(st);
508 static void usb_uas_handle_control(USBDevice *dev, USBPacket *p,
509 int request, int value, int index, int length, uint8_t *data)
511 int ret;
513 ret = usb_desc_handle_control(dev, p, request, value, index, length, data);
514 if (ret >= 0) {
515 return;
517 fprintf(stderr, "%s: unhandled control request\n", __func__);
518 p->status = USB_RET_STALL;
521 static void usb_uas_cancel_io(USBDevice *dev, USBPacket *p)
523 UASDevice *uas = DO_UPCAST(UASDevice, dev, dev);
524 UASRequest *req, *nreq;
526 if (uas->status == p) {
527 uas->status = NULL;
528 qemu_bh_cancel(uas->status_bh);
529 return;
531 QTAILQ_FOREACH_SAFE(req, &uas->requests, next, nreq) {
532 if (req->data == p) {
533 req->data = NULL;
534 return;
537 assert(!"canceled usb packet not found");
540 static void usb_uas_command(UASDevice *uas, uas_ui *ui)
542 UASRequest *req;
543 uint32_t len;
545 req = usb_uas_find_request(uas, be16_to_cpu(ui->hdr.tag));
546 if (req) {
547 goto overlapped_tag;
549 req = usb_uas_alloc_request(uas, ui);
550 if (req->dev == NULL) {
551 goto bad_target;
554 trace_usb_uas_command(uas->dev.addr, req->tag,
555 usb_uas_get_lun(req->lun),
556 req->lun >> 32, req->lun & 0xffffffff);
557 QTAILQ_INSERT_TAIL(&uas->requests, req, next);
558 req->req = scsi_req_new(req->dev, req->tag,
559 usb_uas_get_lun(req->lun),
560 ui->command.cdb, req);
561 len = scsi_req_enqueue(req->req);
562 if (len) {
563 req->data_size = len;
564 scsi_req_continue(req->req);
566 return;
568 overlapped_tag:
569 usb_uas_queue_response(uas, req->tag, UAS_RC_OVERLAPPED_TAG, 0);
570 return;
572 bad_target:
574 * FIXME: Seems to upset linux, is this wrong?
575 * NOTE: Happens only with no scsi devices at the bus, not sure
576 * this is a valid UAS setup in the first place.
578 usb_uas_queue_response(uas, req->tag, UAS_RC_INVALID_INFO_UNIT, 0);
579 g_free(req);
582 static void usb_uas_task(UASDevice *uas, uas_ui *ui)
584 uint16_t tag = be16_to_cpu(ui->hdr.tag);
585 uint64_t lun64 = be64_to_cpu(ui->task.lun);
586 SCSIDevice *dev = usb_uas_get_dev(uas, lun64);
587 int lun = usb_uas_get_lun(lun64);
588 UASRequest *req;
589 uint16_t task_tag;
591 req = usb_uas_find_request(uas, be16_to_cpu(ui->hdr.tag));
592 if (req) {
593 goto overlapped_tag;
596 switch (ui->task.function) {
597 case UAS_TMF_ABORT_TASK:
598 task_tag = be16_to_cpu(ui->task.task_tag);
599 trace_usb_uas_tmf_abort_task(uas->dev.addr, tag, task_tag);
600 if (dev == NULL) {
601 goto bad_target;
603 if (dev->lun != lun) {
604 goto incorrect_lun;
606 req = usb_uas_find_request(uas, task_tag);
607 if (req && req->dev == dev) {
608 scsi_req_cancel(req->req);
610 usb_uas_queue_response(uas, tag, UAS_RC_TMF_COMPLETE, 0);
611 break;
613 case UAS_TMF_LOGICAL_UNIT_RESET:
614 trace_usb_uas_tmf_logical_unit_reset(uas->dev.addr, tag, lun);
615 if (dev == NULL) {
616 goto bad_target;
618 if (dev->lun != lun) {
619 goto incorrect_lun;
621 qdev_reset_all(&dev->qdev);
622 usb_uas_queue_response(uas, tag, UAS_RC_TMF_COMPLETE, 0);
623 break;
625 default:
626 trace_usb_uas_tmf_unsupported(uas->dev.addr, tag, ui->task.function);
627 usb_uas_queue_response(uas, tag, UAS_RC_TMF_NOT_SUPPORTED, 0);
628 break;
630 return;
632 overlapped_tag:
633 usb_uas_queue_response(uas, req->tag, UAS_RC_OVERLAPPED_TAG, 0);
634 return;
636 bad_target:
637 /* FIXME: correct? [see long comment in usb_uas_command()] */
638 usb_uas_queue_response(uas, tag, UAS_RC_INVALID_INFO_UNIT, 0);
639 return;
641 incorrect_lun:
642 usb_uas_queue_response(uas, tag, UAS_RC_INCORRECT_LUN, 0);
645 static void usb_uas_handle_data(USBDevice *dev, USBPacket *p)
647 UASDevice *uas = DO_UPCAST(UASDevice, dev, dev);
648 uas_ui ui;
649 UASStatus *st;
650 UASRequest *req;
651 int length;
653 switch (p->ep->nr) {
654 case UAS_PIPE_ID_COMMAND:
655 length = MIN(sizeof(ui), p->iov.size);
656 usb_packet_copy(p, &ui, length);
657 switch (ui.hdr.id) {
658 case UAS_UI_COMMAND:
659 usb_uas_command(uas, &ui);
660 break;
661 case UAS_UI_TASK_MGMT:
662 usb_uas_task(uas, &ui);
663 break;
664 default:
665 fprintf(stderr, "%s: unknown command ui: id 0x%x\n",
666 __func__, ui.hdr.id);
667 p->status = USB_RET_STALL;
668 break;
670 break;
671 case UAS_PIPE_ID_STATUS:
672 st = QTAILQ_FIRST(&uas->results);
673 if (st == NULL) {
674 assert(uas->status == NULL);
675 uas->status = p;
676 p->status = USB_RET_ASYNC;
677 break;
679 usb_packet_copy(p, &st->status, st->length);
680 QTAILQ_REMOVE(&uas->results, st, next);
681 g_free(st);
682 break;
683 case UAS_PIPE_ID_DATA_IN:
684 case UAS_PIPE_ID_DATA_OUT:
685 req = (p->ep->nr == UAS_PIPE_ID_DATA_IN) ? uas->datain : uas->dataout;
686 if (req == NULL) {
687 fprintf(stderr, "%s: no inflight request\n", __func__);
688 p->status = USB_RET_STALL;
689 break;
691 scsi_req_ref(req->req);
692 req->data = p;
693 usb_uas_copy_data(req);
694 if (p->actual_length == p->iov.size || req->complete) {
695 req->data = NULL;
696 } else {
697 req->data_async = true;
698 p->status = USB_RET_ASYNC;
700 scsi_req_unref(req->req);
701 usb_uas_start_next_transfer(uas);
702 break;
703 default:
704 fprintf(stderr, "%s: invalid endpoint %d\n", __func__, p->ep->nr);
705 p->status = USB_RET_STALL;
706 break;
710 static void usb_uas_handle_destroy(USBDevice *dev)
712 UASDevice *uas = DO_UPCAST(UASDevice, dev, dev);
714 qemu_bh_delete(uas->status_bh);
717 static int usb_uas_init(USBDevice *dev)
719 UASDevice *uas = DO_UPCAST(UASDevice, dev, dev);
721 usb_desc_create_serial(dev);
722 usb_desc_init(dev);
724 QTAILQ_INIT(&uas->results);
725 QTAILQ_INIT(&uas->requests);
726 uas->status_bh = qemu_bh_new(usb_uas_send_status_bh, uas);
728 scsi_bus_new(&uas->bus, &uas->dev.qdev, &usb_uas_scsi_info);
730 return 0;
733 static const VMStateDescription vmstate_usb_uas = {
734 .name = "usb-uas",
735 .unmigratable = 1,
736 .fields = (VMStateField[]) {
737 VMSTATE_USB_DEVICE(dev, UASDevice),
738 VMSTATE_END_OF_LIST()
742 static void usb_uas_class_initfn(ObjectClass *klass, void *data)
744 DeviceClass *dc = DEVICE_CLASS(klass);
745 USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
747 uc->init = usb_uas_init;
748 uc->product_desc = desc_strings[STR_PRODUCT];
749 uc->usb_desc = &desc;
750 uc->cancel_packet = usb_uas_cancel_io;
751 uc->handle_attach = usb_desc_attach;
752 uc->handle_reset = usb_uas_handle_reset;
753 uc->handle_control = usb_uas_handle_control;
754 uc->handle_data = usb_uas_handle_data;
755 uc->handle_destroy = usb_uas_handle_destroy;
756 dc->fw_name = "storage";
757 dc->vmsd = &vmstate_usb_uas;
760 static TypeInfo uas_info = {
761 .name = "usb-uas",
762 .parent = TYPE_USB_DEVICE,
763 .instance_size = sizeof(UASDevice),
764 .class_init = usb_uas_class_initfn,
767 static void usb_uas_register_types(void)
769 type_register_static(&uas_info);
772 type_init(usb_uas_register_types)