[PATCH v3 00/14] scsi: add quirks and features to support m68k Macs

Mark Cave-Ayland posted 14 patches 1 year, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20220622105314.802852-1-mark.cave-ayland@ilande.co.uk
Maintainers: Laurent Vivier <laurent@vivier.eu>, Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>
hw/m68k/q800.c           | 16 +++++++
hw/scsi/scsi-disk.c      | 96 +++++++++++++++++++++++++++++++++++++---
hw/scsi/trace-events     |  3 ++
include/hw/scsi/scsi.h   |  6 +++
include/scsi/constants.h |  2 +
5 files changed, 116 insertions(+), 7 deletions(-)
[PATCH v3 00/14] scsi: add quirks and features to support m68k Macs
Posted by Mark Cave-Ayland 1 year, 10 months ago
Here are the next set of patches from my ongoing work to allow the q800
machine to boot MacOS related to SCSI devices.

Patch 1 adds a new quirks bitmap to SCSIDiskState to allow buggy and/or
legacy features to enabled on an individual device basis. Once the quirks
bitmap has been added, patch 2 uses the quirks feature to implement an
Apple-specific mode page which is required to allow the disk to be recognised
and used by Apple HD SC Setup.

Patch 3 adds compat_props to the q800 machine which enable the new
MODE_PAGE_APPLE_VENDOR quirk for all scsi-cd devices attached to the machine.

Patch 4 adds a new quirk to force SCSI CDROMs to always honour the block
descriptor for a MODE SENSE command which is expected by A/UX, whilst patch 5
enables the quirk for all scsi-cd devices on the q800 machine.

Patches 6 and 7 implement a new MODE_PAGE_VENDOR_SPECIFIC_APPLE quirk to
allow PF=0 MODE SELECT requests which are used by both MacOS and A/UX, along
with a MODE_PAGE_VENDOR_SPECIFIC (0x0) mode page compatible with MacOS. Once
again this quirk is only enabled for SCSI devices on the q800 machine.

Patch 8 implements a dummy FORMAT UNIT command which is used by the Apple HD SC
Setup program when preparing an empty disk to install MacOS.

Patches 9 and 10 add support for allowing truncated MODE SELECT requests which are
sent by A/UX when enumerating a SCSI CDROM device. Allowing these broken requests
is protected by a new MODE_PAGE_TRUNCATED quirk which is only enabled for SCSI
CDROM devices attached to the q800 machine.

Patch 11 allows the MODE_PAGE_R_W_ERROR AWRE bit to be changeable since the A/UX
MODE SELECT request sets this bit to 0 rather than the QEMU default which is 1.

Patch 12 adds support for setting the SCSI block size via a MODE SELECT request
which is most commonly used by older CDROMs to allow the block size to be changed
from the default of 2048 bytes to 512 bytes for compatibility purposes. This is
used by A/UX which otherwise fails with SCSI errors if the block size is not set
to 512 bytes when accessing CDROMs.

Finally patches 13 and 14 augment the compat_props to set the default vendor,
product and version information for all scsi-hd and scsi-cd devices attached
to the q800 machine, taken from real drives. This is because MacOS will only
allow a known set of SCSI devices to be detected and initialised during the
installation process.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>

v3:
[Note from v2: this series has changed in structure and functionality based upon
bug reports from Howard off-list regarding detection/changing of CDROM media in
both A/UX and MacOS]

- Rearrange order to aid bisecting differences between CDROM and DISK quirks
- Add R-B tags from Laurent and Phil
- Replace %zd with %zu in trace-events in patch 8
- Add a new SCSI_DISK_QUIRK_MODE_PAGE_TRUNCATED quirk to handle truncated MODE SELECT
  requests
- Rename SCSI_DISK_QUIRK_MODE_SENSE_ROM_FORCE_DBD quirk to
  SCSI_DISK_QUIRK_MODE_SENSE_ROM_USE_DBD since due to additional changes in this series
  the DBD bit can be honoured rather than forced off
- Add support for PF=0 MODE SELECT commands a and new MODE_PAGE_VENDOR_SPECIFIC (0x0) page
  with a suitable implementation for MacOS protected by a new
  SCSI_DISK_QUIRK_MODE_PAGE_VENDOR_SPECIFIC_APPLE quirk (this fixes detection of CDROM
  media in some cases)
- Allow the SCSI block size to be set for both CDROMs and DISKs as requested by Paolo

v2:
- Change patchset title from "scsi: add support for FORMAT UNIT command and quirks"
  to "scsi: add quirks and features to support m68k Macs"
- Fix missing shift in patch 2 as pointed out by Fam
- Rename MODE_PAGE_APPLE to MODE_PAGE_APPLE_VENDOR
- Add SCSI_DISK_QUIRK_MODE_SENSE_ROM_FORCE_DBD quirk
- Add support for truncated MODE SELECT requests
- Allow MODE_PAGE_R_W_ERROR AWRE bit to be changeable for CDROM devices
- Allow the MODE SELECT block descriptor to set the CDROM block size


Mark Cave-Ayland (14):
  scsi-disk: add new quirks bitmap to SCSIDiskState
  scsi-disk: add MODE_PAGE_APPLE_VENDOR quirk for Macintosh
  q800: implement compat_props to enable quirk_mode_page_apple_vendor
    for scsi-cd devices
  scsi-disk: add SCSI_DISK_QUIRK_MODE_SENSE_ROM_USE_DBD quirk for
    Macintosh
  q800: implement compat_props to enable quirk_mode_sense_rom_use_dbd
    for scsi-cd devices
  scsi-disk: add SCSI_DISK_QUIRK_MODE_PAGE_VENDOR_SPECIFIC_APPLE quirk
    for Macintosh
  q800: implement compat_props to enable
    quirk_mode_page_vendor_specific_apple for scsi devices
  scsi-disk: add FORMAT UNIT command
  scsi-disk: add SCSI_DISK_QUIRK_MODE_PAGE_TRUNCATED quirk for Macintosh
  q800: implement compat_props to enable quirk_mode_page_truncated for
    scsi-cd devices
  scsi-disk: allow the MODE_PAGE_R_W_ERROR AWRE bit to be changeable for
    CDROM drives
  scsi-disk: allow MODE SELECT block descriptor to set the block size
  q800: add default vendor and product information for scsi-hd devices
  q800: add default vendor and product information for scsi-cd devices

 hw/m68k/q800.c           | 16 +++++++
 hw/scsi/scsi-disk.c      | 96 +++++++++++++++++++++++++++++++++++++---
 hw/scsi/trace-events     |  3 ++
 include/hw/scsi/scsi.h   |  6 +++
 include/scsi/constants.h |  2 +
 5 files changed, 116 insertions(+), 7 deletions(-)

-- 
2.30.2
Re: [PATCH v3 00/14] scsi: add quirks and features to support m68k Macs
Posted by Paolo Bonzini 1 year, 9 months ago
Queued, thanks (I was on vacation last week).

I am a bit scared about the mode_select_truncated quirk.  My reading
of the code is that the MODE SELECT would fail anyway because the
page length does not match in scsi_disk_check_mode_select:

    len = mode_sense_page(s, page, &p, 0);
    if (len < 0 || len != expected_len) {
        return -1;
    }

Is that correct?  If not, I'm not sure where I am wrong.  If so,
I wonder if it is enough for the quirk to do just a "goto invalid_param;" 
in place of invalid_param_len.

Thanks,

Paolo
Re: [PATCH v3 00/14] scsi: add quirks and features to support m68k Macs
Posted by Mark Cave-Ayland 1 year, 9 months ago
On 12/07/2022 15:48, Paolo Bonzini wrote:

> Queued, thanks (I was on vacation last week).
> 
> I am a bit scared about the mode_select_truncated quirk.  My reading
> of the code is that the MODE SELECT would fail anyway because the
> page length does not match in scsi_disk_check_mode_select:
> 
>      len = mode_sense_page(s, page, &p, 0);
>      if (len < 0 || len != expected_len) {
>          return -1;
>      }
> 
> Is that correct?  If not, I'm not sure where I am wrong.  If so,
> I wonder if it is enough for the quirk to do just a "goto invalid_param;"
> in place of invalid_param_len.

(goes and looks)

The truncated MODE SELECT request in question seems to be only used by the initial 
A/UX installation image and looks like this:

scsi_req_parsed target 3 lun 0 tag 0 command 21 dir 2 length 20
scsi_req_parsed_lba target 3 lun 0 tag 0 command 21 lba 0
scsi_req_alloc target 3 lun 0 tag 0
scsi_disk_new_request Command: lun=0 tag=0x0 data= 0x15 0x00 0x00 0x00 0x14 0x00
scsi_disk_emulate_command_MODE_SELECT Mode Select(6) (len 20)
scsi_req_continue target 3 lun 0 tag 0
scsi_disk_emulate_write_data Write buf_len=20
scsi_req_data target 3 lun 0 tag 0 len 20
scsi_req_continue target 3 lun 0 tag 0

This includes an 8 byte block descriptor which is used to set the CDROM sector size 
to 512 bytes and so the request content looks like:

4 bytes hdr_len for MODE SELECT(6)
8 bytes bd_len for the block descriptor
8 bytes of data for page 0 (MODE_PAGE_R_W_ERROR) data with page_len = 10

Stepping through mode_select_pages() in the debugger shows that since page_len is set 
correctly to 10 bytes (which matches the expected length in mode_sense_page()) the 
above check succeeds.

I suspect what happened is that the original author built the MODE_PAGE_R_W_ERROR 
page data correctly but miscalculated the length of the request in the CDB. Given 
that the truncated request is seemingly accepted on real hardware, no-one actually 
noticed until now :)


ATB,

Mark.
Re: [PATCH v3 00/14] scsi: add quirks and features to support m68k Macs
Posted by Mark Cave-Ayland 1 year, 10 months ago
On 22/06/2022 11:53, Mark Cave-Ayland wrote:

> Here are the next set of patches from my ongoing work to allow the q800
> machine to boot MacOS related to SCSI devices.
> 
> Patch 1 adds a new quirks bitmap to SCSIDiskState to allow buggy and/or
> legacy features to enabled on an individual device basis. Once the quirks
> bitmap has been added, patch 2 uses the quirks feature to implement an
> Apple-specific mode page which is required to allow the disk to be recognised
> and used by Apple HD SC Setup.
> 
> Patch 3 adds compat_props to the q800 machine which enable the new
> MODE_PAGE_APPLE_VENDOR quirk for all scsi-cd devices attached to the machine.
> 
> Patch 4 adds a new quirk to force SCSI CDROMs to always honour the block
> descriptor for a MODE SENSE command which is expected by A/UX, whilst patch 5
> enables the quirk for all scsi-cd devices on the q800 machine.
> 
> Patches 6 and 7 implement a new MODE_PAGE_VENDOR_SPECIFIC_APPLE quirk to
> allow PF=0 MODE SELECT requests which are used by both MacOS and A/UX, along
> with a MODE_PAGE_VENDOR_SPECIFIC (0x0) mode page compatible with MacOS. Once
> again this quirk is only enabled for SCSI devices on the q800 machine.
> 
> Patch 8 implements a dummy FORMAT UNIT command which is used by the Apple HD SC
> Setup program when preparing an empty disk to install MacOS.
> 
> Patches 9 and 10 add support for allowing truncated MODE SELECT requests which are
> sent by A/UX when enumerating a SCSI CDROM device. Allowing these broken requests
> is protected by a new MODE_PAGE_TRUNCATED quirk which is only enabled for SCSI
> CDROM devices attached to the q800 machine.
> 
> Patch 11 allows the MODE_PAGE_R_W_ERROR AWRE bit to be changeable since the A/UX
> MODE SELECT request sets this bit to 0 rather than the QEMU default which is 1.
> 
> Patch 12 adds support for setting the SCSI block size via a MODE SELECT request
> which is most commonly used by older CDROMs to allow the block size to be changed
> from the default of 2048 bytes to 512 bytes for compatibility purposes. This is
> used by A/UX which otherwise fails with SCSI errors if the block size is not set
> to 512 bytes when accessing CDROMs.
> 
> Finally patches 13 and 14 augment the compat_props to set the default vendor,
> product and version information for all scsi-hd and scsi-cd devices attached
> to the q800 machine, taken from real drives. This is because MacOS will only
> allow a known set of SCSI devices to be detected and initialised during the
> installation process.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> 
> v3:
> [Note from v2: this series has changed in structure and functionality based upon
> bug reports from Howard off-list regarding detection/changing of CDROM media in
> both A/UX and MacOS]
> 
> - Rearrange order to aid bisecting differences between CDROM and DISK quirks
> - Add R-B tags from Laurent and Phil
> - Replace %zd with %zu in trace-events in patch 8
> - Add a new SCSI_DISK_QUIRK_MODE_PAGE_TRUNCATED quirk to handle truncated MODE SELECT
>    requests
> - Rename SCSI_DISK_QUIRK_MODE_SENSE_ROM_FORCE_DBD quirk to
>    SCSI_DISK_QUIRK_MODE_SENSE_ROM_USE_DBD since due to additional changes in this series
>    the DBD bit can be honoured rather than forced off
> - Add support for PF=0 MODE SELECT commands a and new MODE_PAGE_VENDOR_SPECIFIC (0x0) page
>    with a suitable implementation for MacOS protected by a new
>    SCSI_DISK_QUIRK_MODE_PAGE_VENDOR_SPECIFIC_APPLE quirk (this fixes detection of CDROM
>    media in some cases)
> - Allow the SCSI block size to be set for both CDROMs and DISKs as requested by Paolo
> 
> v2:
> - Change patchset title from "scsi: add support for FORMAT UNIT command and quirks"
>    to "scsi: add quirks and features to support m68k Macs"
> - Fix missing shift in patch 2 as pointed out by Fam
> - Rename MODE_PAGE_APPLE to MODE_PAGE_APPLE_VENDOR
> - Add SCSI_DISK_QUIRK_MODE_SENSE_ROM_FORCE_DBD quirk
> - Add support for truncated MODE SELECT requests
> - Allow MODE_PAGE_R_W_ERROR AWRE bit to be changeable for CDROM devices
> - Allow the MODE SELECT block descriptor to set the CDROM block size
> 
> 
> Mark Cave-Ayland (14):
>    scsi-disk: add new quirks bitmap to SCSIDiskState
>    scsi-disk: add MODE_PAGE_APPLE_VENDOR quirk for Macintosh
>    q800: implement compat_props to enable quirk_mode_page_apple_vendor
>      for scsi-cd devices
>    scsi-disk: add SCSI_DISK_QUIRK_MODE_SENSE_ROM_USE_DBD quirk for
>      Macintosh
>    q800: implement compat_props to enable quirk_mode_sense_rom_use_dbd
>      for scsi-cd devices
>    scsi-disk: add SCSI_DISK_QUIRK_MODE_PAGE_VENDOR_SPECIFIC_APPLE quirk
>      for Macintosh
>    q800: implement compat_props to enable
>      quirk_mode_page_vendor_specific_apple for scsi devices
>    scsi-disk: add FORMAT UNIT command
>    scsi-disk: add SCSI_DISK_QUIRK_MODE_PAGE_TRUNCATED quirk for Macintosh
>    q800: implement compat_props to enable quirk_mode_page_truncated for
>      scsi-cd devices
>    scsi-disk: allow the MODE_PAGE_R_W_ERROR AWRE bit to be changeable for
>      CDROM drives
>    scsi-disk: allow MODE SELECT block descriptor to set the block size
>    q800: add default vendor and product information for scsi-hd devices
>    q800: add default vendor and product information for scsi-cd devices
> 
>   hw/m68k/q800.c           | 16 +++++++
>   hw/scsi/scsi-disk.c      | 96 +++++++++++++++++++++++++++++++++++++---
>   hw/scsi/trace-events     |  3 ++
>   include/hw/scsi/scsi.h   |  6 +++
>   include/scsi/constants.h |  2 +
>   5 files changed, 116 insertions(+), 7 deletions(-)

Ping?


ATB,

Mark.