scsi boot
cover scsi boot
Hi,
This patch series adds more scsi support to seabios. I've hacked up a UAS (usb attached scsi) driver, so you can boot from upcoming[1] uas devices. And while being at it I also added lsi53c895a support, allowing qemu boot from lsi without depending on the extboot hack.
enjoy,
Gerd
PS: I'll be offline for two weeks starting next monday, will deal
with review comments once I'm back. Unless someone else is faster or the patches are committed meanwhile ;)
[1] Pull request pending, bits are available from
git://git.kraxel.org/qemu usb.57
Gerd Hoffmann (2):
usb attached scsi boot support
lsi53c895a boot support
Makefile | 3 +- src/Kconfig | 14 +++- src/block.c | 4 +- src/blockcmd.c | 8 ++- src/disk.h | 2 + src/lsi-scsi.c | 213 +++++++++++++++++++++++++++++++++++++++++++++ src/lsi-scsi.h | 2 + src/post.c | 2 + src/usb-uas.c | 264 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/usb-uas.h | 2 + src/usb.c | 10 ++- 11 files changed, 517 insertions(+), 7 deletions(-) create mode 100644 src/lsi-scsi.c create mode 100644 src/lsi-scsi.h create mode 100644 src/usb-uas.c create mode 100644 src/usb-uas.h
PATCH 1/2 usb attached scsi boot support
This patch adds support for booting from UAS (usb attached scsi) devices.
For now only usb 2.0 support is there. On usb 3.0 the UAS protocol uses streams, so changes will be required to make usb 3.0 devices fly once we have a xhci host controller driver.
So far the driver has been tested on qemu-emulated virtual hardware only. In theory should just work on bare metal too.
--- Makefile | 3 +- src/Kconfig | 8 ++- src/block.c | 3 +- src/blockcmd.c | 5 +- src/disk.h | 1 + src/usb-uas.c | 264 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/usb-uas.h | 2 + src/usb.c | 10 ++- 8 files changed, 289 insertions(+), 7 deletions(-) create mode 100644 src/usb-uas.c create mode 100644 src/usb-uas.h
Makefile +2 -1
@@ -12,7 +12,8 @@ SRCBOTH=misc.c stacks.c pmm.c output.c util.c block.c floppy.c ata.c mouse.c \ kbd.c pci.c serial.c clock.c pic.c cdrom.c ps2port.c smp.c resume.c \ pnpbios.c pirtable.c vgahooks.c ramdisk.c pcibios.c blockcmd.c \ usb.c usb-uhci.c usb-ohci.c usb-ehci.c usb-hid.c usb-msc.c \ - virtio-ring.c virtio-pci.c virtio-blk.c virtio-scsi.c apm.c ahci.c + virtio-ring.c virtio-pci.c virtio-blk.c virtio-scsi.c apm.c ahci.c \ + usb-uas.c SRC16=$(SRCBOTH) system.c disk.c font.c SRC32FLAT=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \ acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \
src/Kconfig +7 -1
@@ -161,7 +161,13 @@ menu "Hardware support" bool "USB drives" default y help - Support USB disks. + Support USB BOT (bulk-only transport) disks. + config USB_UAS + depends on USB && DRIVES + bool "UAS drives" + default y + help + Support USB UAS (usb attached scsi) disks. config USB_HUB depends on USB bool "USB hubs"
src/block.c +2 -1
@@ -280,7 +280,7 @@ map_floppy_drive(struct drive_s *drive_g)static int process_scsi_op (struct disk_op_s *op) { -if (!CONFIG_VIRTIO_SCSI && !CONFIG_USB_MSC ) +if (!CONFIG_VIRTIO_SCSI && !CONFIG_USB_MSC && !CONFIG_USB_UAS )return 0 ;switch (op->command) {case CMD_READ :
@@ -321,6 +321,7 @@ process_op(struct disk_op_s *op)case DTYPE_AHCI :return process_ahci_op (op);case DTYPE_USB : +case DTYPE_UAS :case DTYPE_VIRTIO_SCSI :return process_scsi_op (op);default :
src/blockcmd.c +4 -1
@@ -12,6 +12,7 @@#include "ata.h" // atapi_cmd_data #include "ahci.h" // atapi_cmd_data #include "usb-msc.h" // usb_cmd_data +#include "usb-uas.h" // usb_cmd_data #include "virtio-scsi.h" // virtio_scsi_cmd_data #include "boot.h" // boot_add_hd
@@ -25,6 +26,8 @@ cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize)return atapi_cmd_data (op, cdbcmd, blocksize);case DTYPE_USB :return usb_cmd_data (op, cdbcmd, blocksize); +case DTYPE_UAS : +return uas_cmd_data (op, cdbcmd, blocksize);case DTYPE_AHCI :return ahci_cmd_data (op, cdbcmd, blocksize);case DTYPE_VIRTIO_SCSI :
@@ -90,7 +93,7 @@ scsi_is_ready(struct disk_op_s *op)int scsi_init_drive (struct drive_s *drive,const char *s,int prio) { -if (!CONFIG_USB_MSC && !CONFIG_VIRTIO_SCSI ) +if (!CONFIG_USB_UAS && !CONFIG_USB_MSC && !CONFIG_VIRTIO_SCSI )return 0 ;struct disk_op_s dop;
src/disk.h +1 -0
@@ -231,6 +231,7 @@ struct drive_s {#define DTYPE_VIRTIO_SCSI 0x07#define DTYPE_VIRTIO_BLK 0x08#define DTYPE_USB 0x09 +#define DTYPE_UAS 0x0a#define MAXDESCSIZE 80
src/usb-uas.c new file +264 -0
264 lines not on this page · raw message
src/usb-uas.h new file +2 -0
@@ -0,0 +1,2 @@ +int uas_cmd_data (struct disk_op_s *op,void *cdbcmd,u16 blocksize); +int usb_uas_init (struct usbdevice_s *usbdev);
src/usb.c +7 -3
@@ -15,6 +15,7 @@#include "usb-hid.h" // usb_keyboard_setup #include "usb-hub.h" // usb_hub_init #include "usb-msc.h" // usb_msc_init +#include "usb-uas.h" // usb_uas_init #include "usb.h" // struct usb_s #include "biosvar.h" // GET_GLOBAL
@@ -323,9 +324,12 @@ configure_usb_device(struct usbdevice_s *usbdev) usbdev->imax = (void *)config + config->wTotalLength - (void *)iface;if (iface->bInterfaceClass ==USB_CLASS_HUB ) ret =usb_hub_init (usbdev); -else if (iface->bInterfaceClass ==USB_CLASS_MASS_STORAGE ) - ret =usb_msc_init (usbdev); -else +else if (iface->bInterfaceClass ==USB_CLASS_MASS_STORAGE ) { +if (iface->bInterfaceProtocol ==0x50 ) + ret =usb_msc_init (usbdev); +if (iface->bInterfaceProtocol ==0x62 ) + ret =usb_uas_init (usbdev); + }else ret =usb_hid_init (usbdev);if (ret) goto fail;
Signature · 1 line
1.7.1
Re: [Qemu-devel] [SeaBIOS] [PATCH 1/2] usb attached scsi boot support
Quoted 11 lines · Gerd Hoffmann
This patch adds support for booting from UAS (usb attached scsi) devices.
For now only usb 2.0 support is there. On usb 3.0 the UAS protocol uses streams, so changes will be required to make usb 3.0 devices fly once we have a xhci host controller driver.
So far the driver has been tested on qemu-emulated virtual hardware only. In theory should just work on bare metal too.
Thanks. Looks good to me. I have a few minor comments below.
[...]
src/block.c map_floppy_drive(struct drive_s *drive_g) · line 283
Quoted 8 lines
src/block.c +1
-1@@ -280,7 +280,7 @@ map_floppy_drive(struct drive_s *drive_g)static int process_scsi_op (struct disk_op_s *op) { -if (!CONFIG_VIRTIO_SCSI && !CONFIG_USB_MSC ) +if (!CONFIG_VIRTIO_SCSI && !CONFIG_USB_MSC && !CONFIG_USB_UAS )
I think I'll submit a patch to drop this config check - it's not really needed.
[...]
Quoted 2 lines
src/blockcmd.c +0
-0
[...]
src/blockcmd.c scsi_is_ready(struct disk_op_s *op) · line 97
Quoted 6 lines
int
scsi_init_drive(struct drive_s *drive, const char *s, int prio){src/blockcmd.c +1
-1-if (!CONFIG_USB_MSC && !CONFIG_VIRTIO_SCSI ) +if (!CONFIG_USB_UAS && !CONFIG_USB_MSC && !CONFIG_VIRTIO_SCSI )return 0 ;
Same here.
[...]
src/blockcmd.c
Quoted 10 lines
src/blockcmd.c +10
-0+int +usb_uas_init (struct usbdevice_s *usbdev) +{ +if (!CONFIG_USB_UAS ) +return -1 ; + +// Verify right kind of device +struct usb_interface_descriptor *iface = usbdev->iface; +if (iface->bInterfaceSubClass !=0x06 || + iface->bInterfaceProtocol !=0x62 ) {
It would be preferable to #define constants for these numbers.
[...]
src/blockcmd.c
Quoted 7 lines
src/blockcmd.c +7
-0+while (desc) { + desc += desc[0 ]; +switch (desc[1 ]) { +case USB_DT_ENDPOINT : + ep = (void *)desc; +break ; +case 0x24 :
Same here.
[...]
src/usb-uas.h line 2
Quoted 5 lines
src/usb-uas.h new file +2
-0@@ -0,0 +1,2 @@ +int uas_cmd_data (struct disk_op_s *op,void *cdbcmd,u16 blocksize); +int usb_uas_init (struct usbdevice_s *usbdev);
Due to SeaBIOS' use of -fcombine during the build, all headers really should have #ifdef guards on them.
[...]
src/usb-uas.h
Quoted 5 lines
src/usb-uas.h new file +5
-0+else if (iface->bInterfaceClass ==USB_CLASS_MASS_STORAGE ) { +if (iface->bInterfaceProtocol ==0x50 ) + ret =usb_msc_init (usbdev); +if (iface->bInterfaceProtocol ==0x62 ) + ret =usb_uas_init (usbdev);
Would prefer #define names.
-Kevin
PATCH 2/2 lsi53c895a boot support
In reply to Gerd HoffmannThis patch adds support for the lsi53c895a scsi host adapter, allowing seabios to boot from scsi disks and cdroms connected to the lsi scsi hba emulated by qemu.
This driver was written by looking at the expectations of qemu's lsi emulation. I have no idea idea how close this is to work on real hardware, and I somehow doubt anyone cares given the age of physical lsi scsi cards. It depends on !COREBOOT for that reason.
--- Makefile | 2 +- src/Kconfig | 6 ++ src/block.c | 3 +- src/blockcmd.c | 5 +- src/disk.h | 1 + src/lsi-scsi.c | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lsi-scsi.h | 2 + src/post.c | 2 + 8 files changed, 231 insertions(+), 3 deletions(-) create mode 100644 src/lsi-scsi.c create mode 100644 src/lsi-scsi.h
Makefile +1 -1
@@ -13,7 +13,7 @@ SRCBOTH=misc.c stacks.c pmm.c output.c util.c block.c floppy.c ata.c mouse.c \ pnpbios.c pirtable.c vgahooks.c ramdisk.c pcibios.c blockcmd.c \ usb.c usb-uhci.c usb-ohci.c usb-ehci.c usb-hid.c usb-msc.c \ virtio-ring.c virtio-pci.c virtio-blk.c virtio-scsi.c apm.c ahci.c \ - usb-uas.c + usb-uas.c lsi-scsi.c SRC16=$(SRCBOTH) system.c disk.c font.c SRC32FLAT=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \ acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \
src/Kconfig +6 -0
@@ -119,6 +119,12 @@ menu "Hardware support" default y help Support boot from virtio-scsi storage. + config LSI_SCSI + depends on DRIVES && !COREBOOT + bool "lsi53c895a scsi controllers" + default y + help + Support boot from lsi53c895a scsi storage. config FLOPPY depends on DRIVES bool "Floppy controller"
src/block.c +2 -1
@@ -280,7 +280,7 @@ map_floppy_drive(struct drive_s *drive_g)static int process_scsi_op (struct disk_op_s *op) { -if (!CONFIG_VIRTIO_SCSI && !CONFIG_USB_MSC && !CONFIG_USB_UAS ) +if (!CONFIG_VIRTIO_SCSI && !CONFIG_USB_MSC && !CONFIG_USB_UAS && !CONFIG_LSI_SCSI )return 0 ;switch (op->command) {case CMD_READ :
@@ -323,6 +323,7 @@ process_op(struct disk_op_s *op)case DTYPE_USB :case DTYPE_UAS :case DTYPE_VIRTIO_SCSI : +case DTYPE_LSI_SCSI :return process_scsi_op (op);default : op->count =0 ;
src/blockcmd.c +4 -1
@@ -14,6 +14,7 @@#include "usb-msc.h" // usb_cmd_data #include "usb-uas.h" // usb_cmd_data #include "virtio-scsi.h" // virtio_scsi_cmd_data +#include "lsi-scsi.h" // lsi_scsi_cmd_data #include "boot.h" // boot_add_hd // Route command to low-level handler.
@@ -32,6 +33,8 @@ cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize)return ahci_cmd_data (op, cdbcmd, blocksize);case DTYPE_VIRTIO_SCSI :return virtio_scsi_cmd_data (op, cdbcmd, blocksize); +case DTYPE_LSI_SCSI : +return lsi_scsi_cmd_data (op, cdbcmd, blocksize);default : op->count =0 ;return DISK_RET_EPARAM ;
@@ -93,7 +96,7 @@ scsi_is_ready(struct disk_op_s *op)int scsi_init_drive (struct drive_s *drive,const char *s,int prio) { -if (!CONFIG_USB_UAS && !CONFIG_USB_MSC && !CONFIG_VIRTIO_SCSI ) +if (!CONFIG_USB_UAS && !CONFIG_USB_MSC && !CONFIG_VIRTIO_SCSI && !CONFIG_LSI_SCSI )return 0 ;struct disk_op_s dop;
src/disk.h +1 -0
@@ -232,6 +232,7 @@ struct drive_s {#define DTYPE_VIRTIO_BLK 0x08#define DTYPE_USB 0x09#define DTYPE_UAS 0x0a +#define DTYPE_LSI_SCSI 0x0b#define MAXDESCSIZE 80
src/lsi-scsi.c new file +213 -0
213 lines not on this page · raw message
src/lsi-scsi.h new file +2 -0
@@ -0,0 +1,2 @@ +void lsi_scsi_setup (void ); +int lsi_scsi_cmd_data (struct disk_op_s *op,void *cdbcmd,u16 blocksize);
src/post.c +2 -0
@@ -27,6 +27,7 @@#include "ps2port.h" // ps2port_setup #include "virtio-blk.h" // virtio_blk_setup #include "virtio-scsi.h" // virtio_scsi_setup +#include "lsi-scsi.h" // lsi_scsi_setup /****************************************************************
@@ -194,6 +195,7 @@ init_hw(void)ramdisk_setup ();virtio_blk_setup ();virtio_scsi_setup (); +lsi_scsi_setup (); }// Begin the boot process by invoking an int0x19 in 16bit mode.
Signature · 1 line
1.7.1
Re: [Qemu-devel] [SeaBIOS] [PATCH 2/2] lsi53c895a boot support
Quoted 8 lines · Gerd Hoffmann
This patch adds support for the lsi53c895a scsi host adapter, allowing seabios to boot from scsi disks and cdroms connected to the lsi scsi hba emulated by qemu.
This driver was written by looking at the expectations of qemu's lsi emulation. I have no idea idea how close this is to work on real hardware, and I somehow doubt anyone cares given the age of physical lsi scsi cards. It depends on !COREBOOT for that reason.
Thanks. Looks good to me. I definitely agree on marking it as !COREBOOT. Some minor comments below.
[...]
src/Kconfig menu "Hardware support" · line 127
Quoted 12 lines
src/Kconfig +6
-0@@ -119,6 +119,12 @@ menu "Hardware support" default y help Support boot from virtio-scsi storage. + config LSI_SCSI + depends on DRIVES && !COREBOOT + bool "lsi53c895a scsi controllers" + default y + help + Support boot from lsi53c895a scsi storage.
It's probably worthwhile to point out in the help that this is for QEMU emulation only.
[...]
Quoted 7 lines
src/Kconfig +7
-0+static int +lsi_scsi_cmd(struct lsi_lun_s *llun, struct disk_op_s *op, + void *cdbcmd, u16 target, u16 lun, u16 blocksize) +{ + u32 iobase = GET_GLOBAL(llun->iobase); + u32 dma = ((cdb_is_read(cdbcmd, blocksize) ? 0x01000000 : 0x00000000) | + (op->count * blocksize));
src/Kconfig menu "Hardware support"
Quoted 10 lines
src/Kconfig +10
-0+ u8 msgout[] = { + 0x80 | lun, // select lun + 0x08, + }; + u8 status = 0xff; + u8 msgin_tmp[2]; + u8 msgin = 0xff; + + /* FIXME: probably not the best idea to have this on the stack ... */ + u32 script[] = {
Several places in the code DMA to the stack already (usb-ehci, usb-uhci, ata).
[...]
src/lsi-scsi.h line 2
Quoted 5 lines
src/lsi-scsi.h new file +2
-0@@ -0,0 +1,2 @@ +void lsi_scsi_setup (void ); +int lsi_scsi_cmd_data (struct disk_op_s *op,void *cdbcmd,u16 blocksize);
Should have a header guard.
-Kevin
Re: [Qemu-devel] [SeaBIOS] [PATCH 2/2] lsi53c895a boot support
Hi,
Quoted 5 lines
src/lsi-scsi.c line 65
Quoted 2 lines
src/lsi-scsi.c new file +2
-0+/* FIXME: probably not the best idea to have this on the stack ... */ +u32 script[] = {Several places in the code DMA to the stack already (usb-ehci, usb-uhci, ata).
My concern isn't DMA'ing to the stack, but the size of the script and possible stack overruns. But maybe it is a moot point with the stack switching added to seabios recently.
cheers,
Gerd
Re: [Qemu-devel] [SeaBIOS] [PATCH 2/2] lsi53c895a boot support
Quoted 11 lines · Gerd Hoffmann
Hi,
Quoted 5 lines
src/lsi-scsi.c line 65
Quoted 2 lines
src/lsi-scsi.c new file +2
-0+/* FIXME: probably not the best idea to have this on the stack ... */ +u32 script[] = {Several places in the code DMA to the stack already (usb-ehci, usb-uhci, ata).
My concern isn't DMA'ing to the stack, but the size of the script and possible stack overruns. But maybe it is a moot point with the stack switching added to seabios recently.
Disk access code will have at least a 4K stack in 32bit mode and a 2K stack in 16bit mode.
-Kevin
Re: [Qemu-devel] [SeaBIOS] [PATCH 2/2] lsi53c895a boot support
Quoted 7 lines · Kevin O'Connor
Quoted 3 lines · Gerd Hoffmann
My concern isn't DMA'ing to the stack, but the size of the script and possible stack overruns. But maybe it is a moot point with the stack switching added to seabios recently.
Disk access code will have at least a 4K stack in 32bit mode and a 2K stack in 16bit mode.
Ok, then, that should be enougth.
thanks,
Gerd