191
static void esp_request_cancelled(SCSIRequest *req)
193
ESPState *s = DO_UPCAST(ESPState, busdev.qdev, req->bus->qbus.parent);
195
if (req == s->current_req) {
196
scsi_req_unref(s->current_req);
197
s->current_req = NULL;
198
s->current_dev = NULL;
190
202
static uint32_t get_cmd(ESPState *s, uint8_t *buf)
233
245
DPRINTF("do_busid_cmd: busid 0x%x\n", busid);
235
datalen = s->current_dev->info->send_command(s->current_dev, 0, buf, lun);
247
s->current_req = scsi_req_new(s->current_dev, 0, lun, NULL);
248
datalen = scsi_req_enqueue(s->current_req, buf);
236
249
s->ti_size = datalen;
237
250
if (datalen != 0) {
238
251
s->rregs[ESP_RSTAT] = STAT_TC;
240
253
s->dma_counter = 0;
241
254
if (datalen > 0) {
242
255
s->rregs[ESP_RSTAT] |= STAT_DI;
243
s->current_dev->info->read_data(s->current_dev, 0);
245
257
s->rregs[ESP_RSTAT] |= STAT_DO;
246
s->current_dev->info->write_data(s->current_dev, 0);
259
scsi_req_continue(s->current_req);
249
261
s->rregs[ESP_RINTR] = INTR_BS | INTR_FC;
250
262
s->rregs[ESP_RSEQ] = SEQ_CD;
307
319
static void write_response(ESPState *s)
309
DPRINTF("Transfer status (sense=%d)\n", s->sense);
310
s->ti_buf[0] = s->sense;
321
DPRINTF("Transfer status (status=%d)\n", s->status);
322
s->ti_buf[0] = s->status;
311
323
s->ti_buf[1] = 0;
313
325
s->dma_memory_write(s->dma_opaque, s->ti_buf, 2);
371
383
s->ti_size -= len;
372
384
if (s->async_len == 0) {
374
// ti_size is negative
375
s->current_dev->info->write_data(s->current_dev, 0);
377
s->current_dev->info->read_data(s->current_dev, 0);
378
/* If there is still data to be read from the device then
379
complete the DMA operation immediately. Otherwise defer
380
until the scsi layer has completed. */
381
if (s->dma_left == 0 && s->ti_size > 0) {
385
scsi_req_continue(s->current_req);
386
/* If there is still data to be read from the device then
387
complete the DMA operation immediately. Otherwise defer
388
until the scsi layer has completed. */
389
if (to_device || s->dma_left != 0 || s->ti_size == 0) {
386
/* Partially filled a scsi buffer. Complete immediately. */
394
/* Partially filled a scsi buffer. Complete immediately. */
391
static void esp_command_complete(SCSIBus *bus, int reason, uint32_t tag,
398
static void esp_command_complete(SCSIRequest *req, uint32_t status)
394
ESPState *s = DO_UPCAST(ESPState, busdev.qdev, bus->qbus.parent);
400
ESPState *s = DO_UPCAST(ESPState, busdev.qdev, req->bus->qbus.parent);
396
if (reason == SCSI_REASON_DONE) {
397
DPRINTF("SCSI Command complete\n");
399
DPRINTF("SCSI command completed unexpectedly\n");
404
DPRINTF("Command failed\n");
406
s->rregs[ESP_RSTAT] = STAT_ST;
402
DPRINTF("SCSI Command complete\n");
403
if (s->ti_size != 0) {
404
DPRINTF("SCSI command completed unexpectedly\n");
410
DPRINTF("Command failed\n");
413
s->rregs[ESP_RSTAT] = STAT_ST;
415
if (s->current_req) {
416
scsi_req_unref(s->current_req);
417
s->current_req = NULL;
408
418
s->current_dev = NULL;
410
DPRINTF("transfer %d/%d\n", s->dma_left, s->ti_size);
412
s->async_buf = s->current_dev->info->get_buf(s->current_dev, 0);
415
} else if (s->dma_counter != 0 && s->ti_size <= 0) {
416
/* If this was the last part of a DMA transfer then the
417
completion interrupt is deferred to here. */
422
static void esp_transfer_data(SCSIRequest *req, uint32_t len)
424
ESPState *s = DO_UPCAST(ESPState, busdev.qdev, req->bus->qbus.parent);
426
DPRINTF("transfer %d/%d\n", s->dma_left, s->ti_size);
428
s->async_buf = scsi_req_get_buf(req);
431
} else if (s->dma_counter != 0 && s->ti_size <= 0) {
432
/* If this was the last part of a DMA transfer then the
433
completion interrupt is deferred to here. */
678
693
VMSTATE_UINT32(ti_rptr, ESPState),
679
694
VMSTATE_UINT32(ti_wptr, ESPState),
680
695
VMSTATE_BUFFER(ti_buf, ESPState),
681
VMSTATE_UINT32(sense, ESPState),
696
VMSTATE_UINT32(status, ESPState),
682
697
VMSTATE_UINT32(dma, ESPState),
683
698
VMSTATE_BUFFER(cmdbuf, ESPState),
684
699
VMSTATE_UINT32(cmdlen, ESPState),
714
729
*dma_enable = qdev_get_gpio_in(dev, 1);
732
static const struct SCSIBusOps esp_scsi_ops = {
733
.transfer_data = esp_transfer_data,
734
.complete = esp_command_complete,
735
.cancel = esp_request_cancelled
717
738
static int esp_init1(SysBusDevice *dev)
719
740
ESPState *s = FROM_SYSBUS(ESPState, dev);
729
750
qdev_init_gpio_in(&dev->qdev, esp_gpio_demux, 2);
731
scsi_bus_new(&s->bus, &dev->qdev, 0, ESP_MAX_DEVS, esp_command_complete);
752
scsi_bus_new(&s->bus, &dev->qdev, 0, ESP_MAX_DEVS, &esp_scsi_ops);
732
753
return scsi_bus_legacy_handle_cmdline(&s->bus);