[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 11/17] esp.c: rework esp_cdb_length() into esp_cdb_ready()
From: |
Mark Cave-Ayland |
Subject: |
[PATCH v3 11/17] esp.c: rework esp_cdb_length() into esp_cdb_ready() |
Date: |
Sun, 24 Mar 2024 19:17:00 +0000 |
The esp_cdb_length() function is only used as part of a calculation to determine
whether the cmdfifo contains an entire SCSI CDB. Rework esp_cdb_length() into a
new esp_cdb_ready() function which both enables us to handle the case where
scsi_cdb_length() returns -1, plus simplify the logic for its callers.
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
hw/scsi/esp.c | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
index f3aa5364cf..f47abc36d6 100644
--- a/hw/scsi/esp.c
+++ b/hw/scsi/esp.c
@@ -425,20 +425,20 @@ static void write_response(ESPState *s)
}
}
-static int esp_cdb_length(ESPState *s)
+static bool esp_cdb_ready(ESPState *s)
{
+ int len = fifo8_num_used(&s->cmdfifo) - s->cmdfifo_cdb_offset;
const uint8_t *pbuf;
- int cmdlen, len;
+ int cdblen;
- cmdlen = fifo8_num_used(&s->cmdfifo);
- if (cmdlen < s->cmdfifo_cdb_offset) {
- return 0;
+ if (len <= 0) {
+ return false;
}
- pbuf = fifo8_peek_buf(&s->cmdfifo, cmdlen, NULL);
- len = scsi_cdb_length((uint8_t *)&pbuf[s->cmdfifo_cdb_offset]);
+ pbuf = fifo8_peek_buf(&s->cmdfifo, len, NULL);
+ cdblen = scsi_cdb_length((uint8_t *)&pbuf[s->cmdfifo_cdb_offset]);
- return len;
+ return cdblen < 0 ? false : (len >= cdblen);
}
static void esp_dma_ti_check(ESPState *s)
@@ -806,10 +806,9 @@ static void esp_do_nodma(ESPState *s)
trace_esp_handle_ti_cmd(cmdlen);
/* CDB may be transferred in one or more TI commands */
- if (esp_cdb_length(s) && esp_cdb_length(s) ==
- fifo8_num_used(&s->cmdfifo) - s->cmdfifo_cdb_offset) {
- /* Command has been received */
- do_cmd(s);
+ if (esp_cdb_ready(s)) {
+ /* Command has been received */
+ do_cmd(s);
} else {
/*
* If data was transferred from the FIFO then raise bus
@@ -832,10 +831,9 @@ static void esp_do_nodma(ESPState *s)
fifo8_push_all(&s->cmdfifo, buf, len);
/* Handle when DMA transfer is terminated by non-DMA FIFO write */
- if (esp_cdb_length(s) && esp_cdb_length(s) ==
- fifo8_num_used(&s->cmdfifo) - s->cmdfifo_cdb_offset) {
- /* Command has been received */
- do_cmd(s);
+ if (esp_cdb_ready(s)) {
+ /* Command has been received */
+ do_cmd(s);
}
break;
--
2.39.2
- Re: [PATCH v3 03/17] esp.c: replace esp_fifo_pop_buf() with esp_fifo8_pop_buf() in do_message_phase(), (continued)
- [PATCH v3 04/17] esp.c: replace cmdfifo use of esp_fifo_pop() in do_message_phase(), Mark Cave-Ayland, 2024/03/24
- [PATCH v3 05/17] esp.c: change esp_fifo_push() to take ESPState, Mark Cave-Ayland, 2024/03/24
- [PATCH v3 07/17] esp.c: use esp_fifo_push() instead of fifo8_push(), Mark Cave-Ayland, 2024/03/24
- [PATCH v3 06/17] esp.c: change esp_fifo_pop() to take ESPState, Mark Cave-Ayland, 2024/03/24
- [PATCH v3 08/17] esp.c: change esp_fifo_pop_buf() to take ESPState, Mark Cave-Ayland, 2024/03/24
- [PATCH v3 09/17] esp.c: introduce esp_fifo_push_buf() function for pushing to the FIFO, Mark Cave-Ayland, 2024/03/24
- [PATCH v3 10/17] esp.c: don't assert() if FIFO empty when executing non-DMA SELATNS, Mark Cave-Ayland, 2024/03/24
- [PATCH v3 11/17] esp.c: rework esp_cdb_length() into esp_cdb_ready(),
Mark Cave-Ayland <=
- [PATCH v3 12/17] esp.c: prevent cmdfifo overflow in esp_cdb_ready(), Mark Cave-Ayland, 2024/03/24
- [PATCH v3 13/17] esp.c: move esp_set_phase() and esp_get_phase() towards the beginning of the file, Mark Cave-Ayland, 2024/03/24
- [PATCH v3 14/17] esp.c: introduce esp_update_drq() and update esp_fifo_{push, pop}_buf() to use it, Mark Cave-Ayland, 2024/03/24
- [PATCH v3 15/17] esp.c: update esp_fifo_{push, pop}() to call esp_update_drq(), Mark Cave-Ayland, 2024/03/24
- [PATCH v3 16/17] esp.c: ensure esp_pdma_write() always calls esp_fifo_push(), Mark Cave-Ayland, 2024/03/24
- [PATCH v3 17/17] esp.c: remove explicit setting of DRQ within ESP state machine, Mark Cave-Ayland, 2024/03/24