Separate out init code from the rest of the 32bit flat code.
[seabios.git] / src / usb-msc.c
index a7047fd253e1cf88e9b0e9daacacf74e1b6e1d98..968cae3914d9149ef57519147ec9c8f906046733 100644 (file)
@@ -111,6 +111,8 @@ fail:
 int
 process_usb_op(struct disk_op_s *op)
 {
+    if (!CONFIG_USB_MSC)
+        return 0;
     switch (op->command) {
     case CMD_READ:
         return cdb_read(op);
@@ -180,25 +182,15 @@ usb_msc_init(struct usb_pipe *pipe
         return -1;
 
     // Verify right kind of device
-    if (iface->bInterfaceSubClass != US_SC_SCSI
+    if ((iface->bInterfaceSubClass != US_SC_SCSI &&
+        iface->bInterfaceSubClass != US_SC_ATAPI_8070 &&
+        iface->bInterfaceSubClass != US_SC_ATAPI_8020)
         || iface->bInterfaceProtocol != US_PR_BULK) {
         dprintf(1, "Unsupported MSC USB device (subclass=%02x proto=%02x)\n"
                 , iface->bInterfaceSubClass, iface->bInterfaceProtocol);
         return -1;
     }
 
-    // Find bulk in and bulk out endpoints.
-    struct usb_endpoint_descriptor *indesc = findEndPointDesc(
-        iface, imax, USB_ENDPOINT_XFER_BULK, USB_DIR_IN);
-    struct usb_endpoint_descriptor *outdesc = findEndPointDesc(
-        iface, imax, USB_ENDPOINT_XFER_BULK, USB_DIR_OUT);
-    if (!indesc || !outdesc)
-        goto fail;
-    struct usb_pipe *bulkin = alloc_bulk_pipe(pipe, indesc);
-    struct usb_pipe *bulkout = alloc_bulk_pipe(pipe, outdesc);
-    if (!bulkin || !bulkout)
-        goto fail;
-
     // Allocate drive structure.
     char *desc = malloc_tmphigh(MAXDESCSIZE);
     struct usbdrive_s *udrive_g = malloc_fseg(sizeof(*udrive_g));
@@ -208,8 +200,18 @@ usb_msc_init(struct usb_pipe *pipe
     }
     memset(udrive_g, 0, sizeof(*udrive_g));
     udrive_g->drive.type = DTYPE_USB;
-    udrive_g->bulkin = bulkin;
-    udrive_g->bulkout = bulkout;
+
+    // Find bulk in and bulk out endpoints.
+    struct usb_endpoint_descriptor *indesc = findEndPointDesc(
+        iface, imax, USB_ENDPOINT_XFER_BULK, USB_DIR_IN);
+    struct usb_endpoint_descriptor *outdesc = findEndPointDesc(
+        iface, imax, USB_ENDPOINT_XFER_BULK, USB_DIR_OUT);
+    if (!indesc || !outdesc)
+        goto fail;
+    udrive_g->bulkin = alloc_bulk_pipe(pipe, indesc);
+    udrive_g->bulkout = alloc_bulk_pipe(pipe, outdesc);
+    if (!udrive_g->bulkin || !udrive_g->bulkout)
+        goto fail;
 
     // Validate drive and find block size and sector count.
     struct disk_op_s dop;