Re: [PATCH v2 09/11] scsi-disk: allow MODE SELECT block descriptor to set the ROM device block size

2022-05-30 Thread Mark Cave-Ayland

On 26/05/2022 13:08, Paolo Bonzini wrote:


On 4/24/22 18:49, Mark Cave-Ayland wrote:

Whilst CDROM drives usually have a 2048 byte sector size, older drives have the
ability to switch between 2048 byte and 512 byte sector sizes by specifying a
block descriptor in the MODE SELECT command.

If a MODE SELECT block descriptor is provided, update the scsi-cd device block
size with the provided value accordingly.

This allows CDROMs to be used with A/UX whose driver only works with a 512 byte
sector size.

Signed-off-by: Mark Cave-Ayland 


Why do this only for MMC?


No good reason other than I only have an guest OS that does this for CDROMs :)  I can 
easily drop the TYPE_ROM check if you don't think it will cause any unexpected issues 
with other SCSI devices?



Paolo


---
  hw/scsi/scsi-disk.c  | 7 +++
  hw/scsi/trace-events | 1 +
  2 files changed, 8 insertions(+)

diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 6991493cf4..41ebbe3045 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -1583,6 +1583,13 @@ static void scsi_disk_emulate_mode_select(SCSIDiskReq *r, 
uint8_t *inbuf)

  goto invalid_param;
  }
+    /* Allow changing the block size of ROM devices */
+    if (s->qdev.type == TYPE_ROM && bd_len &&
+    p[6] != (s->qdev.blocksize >> 8)) {
+    s->qdev.blocksize = p[6] << 8;
+    trace_scsi_disk_mode_select_rom_set_blocksize(s->qdev.blocksize);
+    }
+
  len -= bd_len;
  p += bd_len;
diff --git a/hw/scsi/trace-events b/hw/scsi/trace-events
index 25eae9f307..1a021ddae9 100644
--- a/hw/scsi/trace-events
+++ b/hw/scsi/trace-events
@@ -340,6 +340,7 @@ scsi_disk_dma_command_WRITE(const char *cmd, uint64_t lba, int 
len) "Write %s(se
  scsi_disk_new_request(uint32_t lun, uint32_t tag, const char *line) "Command: 
lun=%d tag=0x%x data=%s"
  scsi_disk_aio_sgio_command(uint32_t tag, uint8_t cmd, uint64_t lba, int len, 
uint32_t timeout) "disk aio sgio: tag=0x%x cmd=0x%x (sector %" PRId64 ", count %d) 
timeout=%u"
  scsi_disk_mode_select_page_truncated(int page, int len, int page_len) "page %d 
expected length %d but received length %d"

+scsi_disk_mode_select_rom_set_blocksize(int blocksize) "set ROM block size to 
%d"
  # scsi-generic.c
  scsi_generic_command_complete_noio(void *req, uint32_t tag, int statuc) "Command 
complete %p tag=0x%x status=%d"



ATB,

Mark.



Re: [PATCH v2 09/11] scsi-disk: allow MODE SELECT block descriptor to set the ROM device block size

2022-05-26 Thread Paolo Bonzini

On 4/24/22 18:49, Mark Cave-Ayland wrote:

Whilst CDROM drives usually have a 2048 byte sector size, older drives have the
ability to switch between 2048 byte and 512 byte sector sizes by specifying a
block descriptor in the MODE SELECT command.

If a MODE SELECT block descriptor is provided, update the scsi-cd device block
size with the provided value accordingly.

This allows CDROMs to be used with A/UX whose driver only works with a 512 byte
sector size.

Signed-off-by: Mark Cave-Ayland 


Why do this only for MMC?

Paolo


---
  hw/scsi/scsi-disk.c  | 7 +++
  hw/scsi/trace-events | 1 +
  2 files changed, 8 insertions(+)

diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 6991493cf4..41ebbe3045 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -1583,6 +1583,13 @@ static void scsi_disk_emulate_mode_select(SCSIDiskReq 
*r, uint8_t *inbuf)
  goto invalid_param;
  }
  
+/* Allow changing the block size of ROM devices */

+if (s->qdev.type == TYPE_ROM && bd_len &&
+p[6] != (s->qdev.blocksize >> 8)) {
+s->qdev.blocksize = p[6] << 8;
+trace_scsi_disk_mode_select_rom_set_blocksize(s->qdev.blocksize);
+}
+
  len -= bd_len;
  p += bd_len;
  
diff --git a/hw/scsi/trace-events b/hw/scsi/trace-events

index 25eae9f307..1a021ddae9 100644
--- a/hw/scsi/trace-events
+++ b/hw/scsi/trace-events
@@ -340,6 +340,7 @@ scsi_disk_dma_command_WRITE(const char *cmd, uint64_t lba, int 
len) "Write %s(se
  scsi_disk_new_request(uint32_t lun, uint32_t tag, const char *line) "Command: 
lun=%d tag=0x%x data=%s"
  scsi_disk_aio_sgio_command(uint32_t tag, uint8_t cmd, uint64_t lba, int len, uint32_t timeout) 
"disk aio sgio: tag=0x%x cmd=0x%x (sector %" PRId64 ", count %d) timeout=%u"
  scsi_disk_mode_select_page_truncated(int page, int len, int page_len) "page %d 
expected length %d but received length %d"
+scsi_disk_mode_select_rom_set_blocksize(int blocksize) "set ROM block size to 
%d"
  
  # scsi-generic.c

  scsi_generic_command_complete_noio(void *req, uint32_t tag, int statuc) "Command 
complete %p tag=0x%x status=%d"





[PATCH v2 09/11] scsi-disk: allow MODE SELECT block descriptor to set the ROM device block size

2022-04-24 Thread Mark Cave-Ayland
Whilst CDROM drives usually have a 2048 byte sector size, older drives have the
ability to switch between 2048 byte and 512 byte sector sizes by specifying a
block descriptor in the MODE SELECT command.

If a MODE SELECT block descriptor is provided, update the scsi-cd device block
size with the provided value accordingly.

This allows CDROMs to be used with A/UX whose driver only works with a 512 byte
sector size.

Signed-off-by: Mark Cave-Ayland 
---
 hw/scsi/scsi-disk.c  | 7 +++
 hw/scsi/trace-events | 1 +
 2 files changed, 8 insertions(+)

diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 6991493cf4..41ebbe3045 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -1583,6 +1583,13 @@ static void scsi_disk_emulate_mode_select(SCSIDiskReq 
*r, uint8_t *inbuf)
 goto invalid_param;
 }
 
+/* Allow changing the block size of ROM devices */
+if (s->qdev.type == TYPE_ROM && bd_len &&
+p[6] != (s->qdev.blocksize >> 8)) {
+s->qdev.blocksize = p[6] << 8;
+trace_scsi_disk_mode_select_rom_set_blocksize(s->qdev.blocksize);
+}
+
 len -= bd_len;
 p += bd_len;
 
diff --git a/hw/scsi/trace-events b/hw/scsi/trace-events
index 25eae9f307..1a021ddae9 100644
--- a/hw/scsi/trace-events
+++ b/hw/scsi/trace-events
@@ -340,6 +340,7 @@ scsi_disk_dma_command_WRITE(const char *cmd, uint64_t lba, 
int len) "Write %s(se
 scsi_disk_new_request(uint32_t lun, uint32_t tag, const char *line) "Command: 
lun=%d tag=0x%x data=%s"
 scsi_disk_aio_sgio_command(uint32_t tag, uint8_t cmd, uint64_t lba, int len, 
uint32_t timeout) "disk aio sgio: tag=0x%x cmd=0x%x (sector %" PRId64 ", count 
%d) timeout=%u"
 scsi_disk_mode_select_page_truncated(int page, int len, int page_len) "page %d 
expected length %d but received length %d"
+scsi_disk_mode_select_rom_set_blocksize(int blocksize) "set ROM block size to 
%d"
 
 # scsi-generic.c
 scsi_generic_command_complete_noio(void *req, uint32_t tag, int statuc) 
"Command complete %p tag=0x%x status=%d"
-- 
2.20.1