esp.c: rework esp_cdb_length() into esp_cdb_ready()
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> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20240324191707.623175-12-mark.cave-ayland@ilande.co.uk> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
This commit is contained in:
parent
5a50644e47
commit
5aa0df4067
@ -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;
|
const uint8_t *pbuf;
|
||||||
int cmdlen, len;
|
int cdblen;
|
||||||
|
|
||||||
cmdlen = fifo8_num_used(&s->cmdfifo);
|
if (len <= 0) {
|
||||||
if (cmdlen < s->cmdfifo_cdb_offset) {
|
return false;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pbuf = fifo8_peek_buf(&s->cmdfifo, cmdlen, NULL);
|
pbuf = fifo8_peek_buf(&s->cmdfifo, len, NULL);
|
||||||
len = scsi_cdb_length((uint8_t *)&pbuf[s->cmdfifo_cdb_offset]);
|
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)
|
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);
|
trace_esp_handle_ti_cmd(cmdlen);
|
||||||
|
|
||||||
/* CDB may be transferred in one or more TI commands */
|
/* CDB may be transferred in one or more TI commands */
|
||||||
if (esp_cdb_length(s) && esp_cdb_length(s) ==
|
if (esp_cdb_ready(s)) {
|
||||||
fifo8_num_used(&s->cmdfifo) - s->cmdfifo_cdb_offset) {
|
/* Command has been received */
|
||||||
/* Command has been received */
|
do_cmd(s);
|
||||||
do_cmd(s);
|
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* If data was transferred from the FIFO then raise bus
|
* 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);
|
fifo8_push_all(&s->cmdfifo, buf, len);
|
||||||
|
|
||||||
/* Handle when DMA transfer is terminated by non-DMA FIFO write */
|
/* Handle when DMA transfer is terminated by non-DMA FIFO write */
|
||||||
if (esp_cdb_length(s) && esp_cdb_length(s) ==
|
if (esp_cdb_ready(s)) {
|
||||||
fifo8_num_used(&s->cmdfifo) - s->cmdfifo_cdb_offset) {
|
/* Command has been received */
|
||||||
/* Command has been received */
|
do_cmd(s);
|
||||||
do_cmd(s);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user