From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Subject: [PULL 14/45] esp: store lun coming from the MESSAGE OUT phase
Date: Thu, 17 Jun 2021 11:31:03 +0200 [thread overview]
Message-ID: <20210617093134.900014-15-pbonzini@redhat.com> (raw)
In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com>
The LUN is selected with an IDENTIFY message, and persists
until the next message out phase. Instead of passing it to
do_busid_cmd, store it in ESPState. Because do_cmd can simply
skip the message out phase if cmdfifo_cdb_offset is zero, it
can now be used for the S without ATN cases as well.
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Tested-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi/esp.c | 47 ++++++++++++++++++++++++++++---------------
hw/scsi/trace-events | 3 ++-
include/hw/scsi/esp.h | 1 +
3 files changed, 34 insertions(+), 17 deletions(-)
diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
index 8fad87be9d..4ac2114788 100644
--- a/hw/scsi/esp.c
+++ b/hw/scsi/esp.c
@@ -221,7 +221,7 @@ static int esp_select(ESPState *s)
/*
* Note that we deliberately don't raise the IRQ here: this will be done
- * either in do_busid_cmd() for DATA OUT transfers or by the deferred
+ * either in do_command_phase() for DATA OUT transfers or by the deferred
* IRQ mechanism in esp_transfer_data() for DATA IN transfers
*/
s->rregs[ESP_RINTR] |= INTR_FC;
@@ -272,24 +272,22 @@ static uint32_t get_cmd(ESPState *s, uint32_t maxlen)
return dmalen;
}
-static void do_busid_cmd(ESPState *s, uint8_t busid)
+static void do_command_phase(ESPState *s)
{
uint32_t cmdlen;
int32_t datalen;
- int lun;
SCSIDevice *current_lun;
uint8_t buf[ESP_CMDFIFO_SZ];
- trace_esp_do_busid_cmd(busid);
- lun = busid & 7;
+ trace_esp_do_command_phase(s->lun);
cmdlen = fifo8_num_used(&s->cmdfifo);
if (!cmdlen || !s->current_dev) {
return;
}
esp_fifo_pop_buf(&s->cmdfifo, buf, cmdlen);
- current_lun = scsi_device_find(&s->bus, 0, s->current_dev->id, lun);
- s->current_req = scsi_req_new(current_lun, 0, lun, buf, s);
+ current_lun = scsi_device_find(&s->bus, 0, s->current_dev->id, s->lun);
+ s->current_req = scsi_req_new(current_lun, 0, s->lun, buf, s);
datalen = scsi_req_enqueue(s->current_req);
s->ti_size = datalen;
fifo8_reset(&s->cmdfifo);
@@ -316,21 +314,29 @@ static void do_busid_cmd(ESPState *s, uint8_t busid)
}
}
-static void do_cmd(ESPState *s)
+static void do_message_phase(ESPState *s)
{
- uint8_t busid = esp_fifo_pop(&s->cmdfifo);
- int len;
+ if (s->cmdfifo_cdb_offset) {
+ uint8_t message = esp_fifo_pop(&s->cmdfifo);
- s->cmdfifo_cdb_offset--;
+ trace_esp_do_identify(message);
+ s->lun = message & 7;
+ s->cmdfifo_cdb_offset--;
+ }
/* Ignore extended messages for now */
if (s->cmdfifo_cdb_offset) {
- len = MIN(s->cmdfifo_cdb_offset, fifo8_num_used(&s->cmdfifo));
+ int len = MIN(s->cmdfifo_cdb_offset, fifo8_num_used(&s->cmdfifo));
esp_fifo_pop_buf(&s->cmdfifo, NULL, len);
s->cmdfifo_cdb_offset = 0;
}
+}
- do_busid_cmd(s, busid);
+static void do_cmd(ESPState *s)
+{
+ do_message_phase(s);
+ assert(s->cmdfifo_cdb_offset == 0);
+ do_command_phase(s);
}
static void satn_pdma_cb(ESPState *s)
@@ -369,7 +375,7 @@ static void s_without_satn_pdma_cb(ESPState *s)
if (!esp_get_tc(s) && !fifo8_is_empty(&s->cmdfifo)) {
s->cmdfifo_cdb_offset = 0;
s->do_cmd = 0;
- do_busid_cmd(s, 0);
+ do_cmd(s);
}
}
@@ -386,7 +392,7 @@ static void handle_s_without_atn(ESPState *s)
if (cmdlen > 0) {
s->cmdfifo_cdb_offset = 0;
s->do_cmd = 0;
- do_busid_cmd(s, 0);
+ do_cmd(s);
} else if (cmdlen == 0) {
s->do_cmd = 1;
/* Target present, but no cmd yet - switch to command phase */
@@ -1131,6 +1137,14 @@ static bool esp_is_version_5(void *opaque, int version_id)
return version_id >= 5;
}
+static bool esp_is_version_6(void *opaque, int version_id)
+{
+ ESPState *s = ESP(opaque);
+
+ version_id = MIN(version_id, s->mig_version_id);
+ return version_id >= 6;
+}
+
int esp_pre_save(void *opaque)
{
ESPState *s = ESP(object_resolve_path_component(
@@ -1168,7 +1182,7 @@ static int esp_post_load(void *opaque, int version_id)
const VMStateDescription vmstate_esp = {
.name = "esp",
- .version_id = 5,
+ .version_id = 6,
.minimum_version_id = 3,
.post_load = esp_post_load,
.fields = (VMStateField[]) {
@@ -1197,6 +1211,7 @@ const VMStateDescription vmstate_esp = {
VMSTATE_FIFO8_TEST(fifo, ESPState, esp_is_version_5),
VMSTATE_FIFO8_TEST(cmdfifo, ESPState, esp_is_version_5),
VMSTATE_UINT8_TEST(ti_cmd, ESPState, esp_is_version_5),
+ VMSTATE_UINT8_TEST(lun, ESPState, esp_is_version_6),
VMSTATE_END_OF_LIST()
},
};
diff --git a/hw/scsi/trace-events b/hw/scsi/trace-events
index 1a27e141ae..92d5b40f89 100644
--- a/hw/scsi/trace-events
+++ b/hw/scsi/trace-events
@@ -166,7 +166,8 @@ esp_dma_disable(void) "Lower enable"
esp_pdma_read(int size) "pDMA read %u bytes"
esp_pdma_write(int size) "pDMA write %u bytes"
esp_get_cmd(uint32_t dmalen, int target) "len %d target %d"
-esp_do_busid_cmd(uint8_t busid) "busid 0x%x"
+esp_do_command_phase(uint8_t busid) "busid 0x%x"
+esp_do_identify(uint8_t byte) "0x%x"
esp_handle_satn_stop(uint32_t cmdlen) "cmdlen %d"
esp_write_response(uint32_t status) "Transfer status (status=%d)"
esp_do_dma(uint32_t cmdlen, uint32_t len) "command len %d + %d"
diff --git a/include/hw/scsi/esp.h b/include/hw/scsi/esp.h
index aada3680b7..b1ec27612f 100644
--- a/include/hw/scsi/esp.h
+++ b/include/hw/scsi/esp.h
@@ -37,6 +37,7 @@ struct ESPState {
SCSIRequest *current_req;
Fifo8 cmdfifo;
uint8_t cmdfifo_cdb_offset;
+ uint8_t lun;
uint32_t do_cmd;
bool data_in_ready;
--
2.31.1
next prev parent reply other threads:[~2021-06-17 9:40 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-17 9:30 [PULL 00/45] Memory, i386, compilation, bugfix changes for 2021-06-17 Paolo Bonzini
2021-06-17 9:30 ` [PULL 01/45] vnc: avoid deprecation warnings for SASL on OS X Paolo Bonzini
2021-06-17 9:30 ` [PULL 02/45] vl: Fix an assert failure in error path Paolo Bonzini
2021-06-17 9:30 ` [PULL 03/45] qemu-config: use qemu_opts_from_qdict Paolo Bonzini
2021-06-17 9:30 ` [PULL 04/45] block/scsi: correctly emulate the VPD block limits page Paolo Bonzini
2021-06-17 9:30 ` [PULL 05/45] runstate: Initialize Error * to NULL Paolo Bonzini
2021-06-17 9:30 ` [PULL 06/45] esp: only assert INTR_DC interrupt flag if selection fails Paolo Bonzini
2021-06-17 9:30 ` [PULL 07/45] esp: only set ESP_RSEQ at the start of the select sequence Paolo Bonzini
2021-06-17 9:30 ` [PULL 08/45] esp: allow non-DMA callback in esp_transfer_data() initial transfer Paolo Bonzini
2021-06-17 9:30 ` [PULL 09/45] esp: handle non-DMA transfers from the target one byte at a time Paolo Bonzini
2021-06-17 9:30 ` [PULL 10/45] esp: ensure PDMA write transfers are flushed from the FIFO to the target immediately Paolo Bonzini
2021-06-17 9:31 ` [PULL 11/45] esp: revert 75ef849696 "esp: correctly fill bus id with requested lun" Paolo Bonzini
2021-06-17 9:31 ` [PULL 12/45] esp: correctly accumulate extended messages for PDMA Paolo Bonzini
2021-06-17 9:31 ` [PULL 13/45] esp: fix migration version check in esp_is_version_5() Paolo Bonzini
2021-06-17 9:31 ` Paolo Bonzini [this message]
2021-06-17 9:31 ` [PULL 15/45] softmmu/physmem: Mark shared anonymous memory RAM_SHARED Paolo Bonzini
2021-06-17 9:31 ` [PULL 16/45] softmmu/physmem: Fix ram_block_discard_range() to handle shared anonymous memory Paolo Bonzini
2021-06-17 9:31 ` [PULL 17/45] softmmu/physmem: Fix qemu_ram_remap() " Paolo Bonzini
2021-06-17 9:31 ` [PULL 18/45] util/mmap-alloc: Factor out calculation of the pagesize for the guard page Paolo Bonzini
2021-06-17 9:31 ` [PULL 19/45] util/mmap-alloc: Factor out reserving of a memory region to mmap_reserve() Paolo Bonzini
2021-06-17 9:31 ` [PULL 20/45] util/mmap-alloc: Factor out activating of memory to mmap_activate() Paolo Bonzini
2021-06-17 9:31 ` [PULL 21/45] softmmu/memory: Pass ram_flags to qemu_ram_alloc_from_fd() Paolo Bonzini
2021-06-17 9:31 ` [PULL 22/45] softmmu/memory: Pass ram_flags to memory_region_init_ram_shared_nomigrate() Paolo Bonzini
2021-06-17 9:31 ` [PULL 23/45] softmmu/memory: Pass ram_flags to qemu_ram_alloc() and qemu_ram_alloc_internal() Paolo Bonzini
2021-06-17 9:31 ` [PULL 24/45] util/mmap-alloc: Pass flags instead of separate bools to qemu_ram_mmap() Paolo Bonzini
2021-06-17 9:31 ` [PULL 25/45] memory: Introduce RAM_NORESERVE and wire it up in qemu_ram_mmap() Paolo Bonzini
2021-06-17 9:31 ` [PULL 26/45] util/mmap-alloc: Support RAM_NORESERVE via MAP_NORESERVE under Linux Paolo Bonzini
2021-06-17 9:31 ` [PULL 27/45] hostmem: Wire up RAM_NORESERVE via "reserve" property Paolo Bonzini
2021-06-17 9:31 ` [PULL 28/45] qmp: Clarify memory backend properties returned via query-memdev Paolo Bonzini
2021-06-17 9:31 ` [PULL 29/45] qmp: Include "share" property of memory backends Paolo Bonzini
2021-06-17 9:31 ` [PULL 30/45] hmp: Print "share" property of memory backends with "info memdev" Paolo Bonzini
2021-06-17 9:31 ` [PULL 31/45] qmp: Include "reserve" property of memory backends Paolo Bonzini
2021-06-17 9:31 ` [PULL 32/45] hmp: Print "reserve" property of memory backends with "info memdev" Paolo Bonzini
2021-06-17 9:31 ` [PULL 33/45] configure: map x32 to cpu_family x86_64 for meson Paolo Bonzini
2021-06-17 9:31 ` [PULL 34/45] target/i386: Refactored intercept checks into cpu_svm_has_intercept Paolo Bonzini
2021-06-17 9:31 ` [PULL 35/45] target/i386: Added consistency checks for VMRUN intercept and ASID Paolo Bonzini
2021-06-17 9:31 ` [PULL 36/45] target/i386: Added consistency checks for CR0 Paolo Bonzini
2021-06-17 9:31 ` [PULL 37/45] target/i386: Added Intercept CR0 writes check Paolo Bonzini
2021-06-17 9:31 ` [PULL 38/45] configure: Use -std=gnu11 Paolo Bonzini
2021-06-17 9:31 ` [PULL 39/45] softfloat: Use _Generic instead of QEMU_GENERIC Paolo Bonzini
2021-06-17 9:31 ` [PULL 40/45] util: Use real functions for thread-posix QemuRecMutex Paolo Bonzini
2021-06-17 9:31 ` [PULL 41/45] util: Pass file+line to qemu_rec_mutex_unlock_impl Paolo Bonzini
2021-06-17 9:31 ` [PULL 42/45] util: Use unique type for QemuRecMutex in thread-posix.h Paolo Bonzini
2021-06-17 9:31 ` [PULL 43/45] include/qemu/lockable: Use _Generic instead of QEMU_GENERIC Paolo Bonzini
2021-06-17 9:31 ` [PULL 44/45] qemu/compiler: Remove QEMU_GENERIC Paolo Bonzini
2021-06-17 9:31 ` [PULL 45/45] configure: Remove probe for _Static_assert Paolo Bonzini
2021-06-17 10:21 ` [PULL 00/45] Memory, i386, compilation, bugfix changes for 2021-06-17 no-reply
2021-06-18 8:53 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210617093134.900014-15-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).