aboutsummaryrefslogtreecommitdiff
path: root/src/hw/blockcmd.c
AgeCommit message (Collapse)AuthorFilesLines
2024-01-26Add LBA 64bit support for reads beyond 2TB.Max Tottenham1-14/+44
When booting from a >2TB drive/filesystem, it's possible what the kernel/bootloader may be updated and written out at an LBA address beyond what is normally accessible by the READ(10) SCSI commands. If this happens to the kernel grub will fail to boot the kernel as it will call into the BIOS with an LBA address >2TB, and the BIOS will return an error. Per the SCSI spec, >2TB drives should return 0XFFFFFFFF, and a READ CAPACITY(16) command should be issued to determine the full size of the drive, READ(16) commands can then be used in order to read data at LBA addresses beyond 2TB (64 bit LBA addresses) Signed-off-by: Max Tottenham <mtottenh@akamai.com> Message-ID: <20240125150050.3775834-2-mtottenh@akamai.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2020-12-21Support booting USB drives with a write protect switch enabledMike Banon1-3/+7
At least some USB drives with a write protect switch (e.g. Netac U335) could report "MEDIUM NOT PRESENT" for a while if a write protection is enabled. Instead of stopping the initialization attempts immediately, stop only after getting this report for 3 times, to ensure the successful initialization of such a "broken hardware". Signed-off-by: Mike Banon <mikebdp2@gmail.com>
2017-09-27block: Rename disk_op_s->drive_gf to drive_flKevin O'Connor1-4/+4
Now that the drive_s struct does not need to be in the f-segment, rename references to drive_gf in the generic drive code to drive_fl. This is just variable renames - no code changes. Tested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-27disk: Don't require the 'struct drive_s' to be in the f-segmentKevin O'Connor1-2/+2
Allow the 'struct drive_s' drive description structure to be in either the "low" memory segment or the f-segment. Tested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-12blockcmd: start REPORT_LUNS with the smallest bufferRoman Kagan1-1/+3
A number of emulated SCSI devices in QEMU incorrectly return an error to REPORT_LUNS command when the size of the data returned is smaller than the allocation length passed in. To work it around, start with the smallest allocation length possible: for 1 entry. This is a slight pessimization because it would require another REPORT_LUNS iteration if the target has more than a single LUN, but this appears to have negligible impact on boot times, and makes REPORT_LUNS enumeration work for more QEMU devices (lsi53c895a, mptsas1068). Reported-by: Maciej Józefczyk <maciej.jozefczyk@corp.ovh.com> Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
2017-05-02blockcmd: generic SCSI luns enumerationRoman Kagan1-0/+94
Add two generic functions to discover active LUNs on a SCSI target. The functions take a temporary drive descriptor on the target, and a callback to create a new drive descriptor with a new LUN using the temporary one as a template. One of the functions performs REPORT LUNS on the temporary drive to obtain the list of candidate luns; the other sequentially iterates the lun numbers up to the given maximum, and is meant as a fallback. Both functions return the number of successfully created drive descriptors, or a negative number if an error occured. This will allow to lift the limitation of most of the SCSI drivers that support booting off the LUN #0 only. Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
2017-05-02blockcmd: accept only disks and CD-ROMsRoman Kagan1-0/+3
Luns that report to INQUIRY with a type other than CD-ROM are considered disks. This isn't necessarily the case; working with such luns as disks may lead to unpredictable results. So bail out if the lun is neither CD-ROM nor disk. Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
2016-08-04blockcmd: CMD_SCSI op is only used in 32bit modeKevin O'Connor1-1/+6
Reduce the size of the 16bit code slightly by recognizing that CMD_SCSI is only used in 32bit mode. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-12-28block: Report drive->sectors using "%u" instead of "%d"Kevin O'Connor1-1/+1
The sector count is a 64bit number that is often reported as a 32bit number (due to limitations in dprintf). Consistently use "%u" reporting to avoid confusing negative numbers. Reported-by: Tobias Diedrich <tobiasdiedrich@gmail.com> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-12-28scsi: Do not call printf() from scsi_is_ready()Kevin O'Connor1-1/+1
The scsi_is_ready() function may be called from a thread, and it is not valid to call printf() from a thread. Convert printf() to dprintf() to avoid this possibility. This does mean that cdrom detection (from cdrom_boot() ) may not give notification of slow cdrom drives to a user. However, the extra medium detection time is unlikely to be large anyway. Reported-by: Tobias Diedrich <tobiasdiedrich@gmail.com> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14blockcmd: Convert cdb_is_read() to scsi_is_read()Kevin O'Connor1-7/+8
Convert the cdb_is_read() function to a new function scsi_is_read() which takes a 'struct disk_op_s' as a paramter. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14blockcmd: Remove unused scsi_process_op() and cdb_cmd_data()Kevin O'Connor1-21/+0
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14pvscsi: Handle pvscsi drives directly via 'struct disk_op_s' requestsKevin O'Connor1-4/+0
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14virtio-scsi: Handle virtio drives directly via 'struct disk_op_s' requestsKevin O'Connor1-4/+0
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14megasas: Handle Megasas drives directly via 'struct disk_op_s' requestsKevin O'Connor1-3/+0
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14esp-scsi: Handle ESP drives directly via 'struct disk_op_s' requestsKevin O'Connor1-3/+0
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14lsi-scsi: Handle LSI drives directly via 'struct disk_op_s' requestsKevin O'Connor1-3/+0
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14usb-uas: Handle USB drives directly via 'struct disk_op_s' requestsKevin O'Connor1-6/+0
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14usb-msc: Handle USB drives directly via 'struct disk_op_s' requestsKevin O'Connor1-6/+0
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14ahci: Handle AHCI ATAPI drives directly via 'struct disk_op_s' requestsKevin O'Connor1-4/+0
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14ata: Handle ATA ATAPI drives directly via 'struct disk_op_s' requestsKevin O'Connor1-3/+0
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14blockcmd: Introduce scsi_fill_cmd()Kevin O'Connor1-30/+23
Introduce scsi_fill_cmd() which creates a scsi style "command data block" from a "struct disk_op_s" disk request. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14block: Route scsi style commands through 'struct disk_op_s'Kevin O'Connor1-5/+22
Support sending scsi style "command data block" commands (cdbcmd) through the 'struct disk_op_s' command request structure. And change the blockcmd.c and cdrom.c code to route these commands through the process_op() code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14block: Introduce default_process_op() with common command handling codesKevin O'Connor1-7/+1
Most disk drivers only implement a couple of the available bios commands. Unify the common fallback handling code into a new function default_process_op() to reduce boiler-plate code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-14block: Split process_op() command dispatch up into multiple functionsKevin O'Connor1-1/+1
Introduce process_op_32(), process_op_16(), and process_op_both() and split the disk driver command dispatch by its runtime mode requirements. This makes it more clear which modes each driver runs in. It also reduces the call32() boiler-plate code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2015-07-01virtio: run drivers in 32bit modeGerd Hoffmann1-2/+3
virtio version 1.0 registers can (and actually do in the qemu implementation) live in mmio space. So we must run the blk and scsi virtio drivers in 32bit mode, otherwise we can't access them. This also allows to drop a bunch of GET_LOWFLAT calls from the virtio code in the following patches. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2014-12-29scsi: Don't export cdb_* functionsKevin O'Connor1-7/+7
The low-level cdb_* functions are now only used from within cmdblock.c, so don't export them. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-12-29scsi: Move process_scsi_op() to hw/blockcmd.c and renameKevin O'Connor1-0/+19
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-12-29scsi: Move cdb_* functions above scsi_* functionsKevin O'Connor1-88/+98
This is just code movement - no code changes. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2014-01-29xhci: Run the XHCI driver entirely in 32bit mode.Kevin O'Connor1-0/+6
Since the XHCI driver needs to jump into 32bit mode anyway, it is simpler to just run all of the code in 32bit mode. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-12-27pvscsi: Always run entirely in 32bit mode.Kevin O'Connor1-1/+2
Instead of jumping into 32bit mode to access the PCI config space, run the entire driver in 32bit mode. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-12-27Remove unnecesary updates of the disk op->count field.Kevin O'Connor1-1/+0
Now that the op->count field is cleared in a global location on simple errors, remove various local clears done in individual drivers. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-10-26Convert op->drive_g from a 16bit pointer to a 32 bit "GLOBALFLAT" pointer.Kevin O'Connor1-6/+6
The "drive" structure is always malloc'ed and therefore always starts off described as a 32-bit "flat" pointer. Instead of switching to/from 16bit pointers, make all the code use the 32bit pointer. This eliminates the confusing 16/32 bit pointer switches. This patch also removes the "_g" suffixes on local variables in functions that are always called in 32bit mode. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-10-26Add pvscsi boot supportEvgeny Budilovsky1-0/+3
Testing was done on windows images (win 2008/2012) taken from esx with vmware tools installed and boot disk configured to use pvscsi. Also I've used linux (ubuntu 12.04) where pvscsi drivers are installed by default and booted it using qemu cmd similar to this: ./x86_64-softmmu/qemu-system-x86_64 -snapshot -device pvscsi,id=pvscsi0 \ -device scsi-disk,bus=pvscsi0.0,drive=drive0 \ -drive id=drive0,if=none,file=ubuntu-12.04.qcow2 \ -bios roms/seabios/out/bios.bin Signed-off-by: Evgeny Budilovsky <evgeny.budilovsky@ravellosystems.com>
2013-10-14Run ahci code entirely in 32bit mode.Kevin O'Connor1-2/+3
The ahci driver needs to jump into 32bit mode in order to access portions of the ahci controllers PCI config space. Instead of jumping into 32bit mode just to toggle the ahci registers, jump into 32bit mode for all of the driver interactions. This shrinks the size of the overall code and can lead to further cleanups. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-10-14Rename fields of 'struct chs_s' and use in floppy lba2chs().Kevin O'Connor1-3/+3
Rename the fields of 'struct chs_s' so that it can be used both to describe a drive and to describe a particular sector on a drive. Update floppy.c:lba2chs() to return a 'struct chs_s' instead of passing the results via pointers. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18Merge bmp.h, boot.h, jpeg.h, and post.h into util.h.Kevin O'Connor1-1/+0
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18Split disk.h into block.h and std/disk.h.Kevin O'Connor1-1/+2
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18Move function definitions for output.c from util.h to new file output.h.Kevin O'Connor1-9/+10
Also, sort the order of include files in the c files. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-18Rename util.c to string.c and introduce string.h.Kevin O'Connor1-0/+1
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2013-09-02Move code centered around specific hardware devices to src/hw/Kevin O'Connor1-0/+278
Move many C files from the src/ directory to the new src/hw/ directory. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>