esp.c: convert esp_do_nodma() to switch statement based upon SCSI phase

Currently only the DATA IN and DATA OUT phases are supported.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Tested-by: Helge Deller <deller@gmx.de>
Tested-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20240112125420.514425-41-mark.cave-ayland@ilande.co.uk>
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
This commit is contained in:
Mark Cave-Ayland 2024-01-12 12:53:32 +00:00
parent 844b3a84ea
commit 9d1aa52b76

View File

@ -786,7 +786,6 @@ static void esp_do_dma(ESPState *s)
static void esp_do_nodma(ESPState *s) static void esp_do_nodma(ESPState *s)
{ {
int to_device = (esp_get_phase(s) == STAT_DO);
uint8_t buf[ESP_FIFO_SZ]; uint8_t buf[ESP_FIFO_SZ];
uint32_t cmdlen; uint32_t cmdlen;
int len, n; int len, n;
@ -823,38 +822,55 @@ static void esp_do_nodma(ESPState *s)
return; return;
} }
if (!s->current_req) { switch (esp_get_phase(s)) {
return; case STAT_DO:
} if (!s->current_req) {
return;
if (s->async_len == 0) { }
/* Defer until data is available. */ if (s->async_len == 0) {
return; /* Defer until data is available. */
} return;
}
if (to_device) {
len = MIN(s->async_len, ESP_FIFO_SZ); len = MIN(s->async_len, ESP_FIFO_SZ);
len = MIN(len, fifo8_num_used(&s->fifo)); len = MIN(len, fifo8_num_used(&s->fifo));
esp_fifo_pop_buf(&s->fifo, s->async_buf, len); esp_fifo_pop_buf(&s->fifo, s->async_buf, len);
s->async_buf += len; s->async_buf += len;
s->async_len -= len; s->async_len -= len;
s->ti_size += len; s->ti_size += len;
} else {
if (s->async_len == 0) {
scsi_req_continue(s->current_req);
return;
}
s->rregs[ESP_RINTR] |= INTR_BS;
esp_raise_irq(s);
break;
case STAT_DI:
if (!s->current_req) {
return;
}
if (s->async_len == 0) {
/* Defer until data is available. */
return;
}
if (fifo8_is_empty(&s->fifo)) { if (fifo8_is_empty(&s->fifo)) {
fifo8_push(&s->fifo, s->async_buf[0]); fifo8_push(&s->fifo, s->async_buf[0]);
s->async_buf++; s->async_buf++;
s->async_len--; s->async_len--;
s->ti_size--; s->ti_size--;
} }
}
if (s->async_len == 0) { if (s->async_len == 0) {
scsi_req_continue(s->current_req); scsi_req_continue(s->current_req);
return; return;
} }
s->rregs[ESP_RINTR] |= INTR_BS; s->rregs[ESP_RINTR] |= INTR_BS;
esp_raise_irq(s); esp_raise_irq(s);
break;
}
} }
static void esp_pdma_cb(ESPState *s) static void esp_pdma_cb(ESPState *s)