Revision c6df7102

b/hw/esp.c
395 395
    esp_dma_done(s);
396 396
}
397 397

  
398
static void esp_command_complete(SCSIRequest *req, int reason, uint32_t arg)
398
static void esp_command_complete(SCSIRequest *req, uint32_t arg)
399 399
{
400 400
    ESPState *s = DO_UPCAST(ESPState, busdev.qdev, req->bus->qbus.parent);
401 401

  
402
    if (reason == SCSI_REASON_DONE) {
403
        DPRINTF("SCSI Command complete\n");
404
        if (s->ti_size != 0)
405
            DPRINTF("SCSI command completed unexpectedly\n");
406
        s->ti_size = 0;
407
        s->dma_left = 0;
408
        s->async_len = 0;
409
        if (arg)
410
            DPRINTF("Command failed\n");
411
        s->status = arg;
412
        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");
405
    }
406
    s->ti_size = 0;
407
    s->dma_left = 0;
408
    s->async_len = 0;
409
    if (arg) {
410
        DPRINTF("Command failed\n");
411
    }
412
    s->status = arg;
413
    s->rregs[ESP_RSTAT] = STAT_ST;
414
    esp_dma_done(s);
415
    if (s->current_req) {
416
        scsi_req_unref(s->current_req);
417
        s->current_req = NULL;
418
        s->current_dev = NULL;
419
    }
420
}
421

  
422
static void esp_transfer_data(SCSIRequest *req, uint32_t arg)
423
{
424
    ESPState *s = DO_UPCAST(ESPState, busdev.qdev, req->bus->qbus.parent);
425

  
426
    DPRINTF("transfer %d/%d\n", s->dma_left, s->ti_size);
427
    s->async_len = arg;
428
    s->async_buf = scsi_req_get_buf(req);
429
    if (s->dma_left) {
430
        esp_do_dma(s);
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.  */
413 434
        esp_dma_done(s);
414
        if (s->current_req) {
415
            scsi_req_unref(s->current_req);
416
            s->current_req = NULL;
417
            s->current_dev = NULL;
418
        }
419
    } else {
420
        DPRINTF("transfer %d/%d\n", s->dma_left, s->ti_size);
421
        s->async_len = arg;
422
        s->async_buf = scsi_req_get_buf(req);
423
        if (s->dma_left) {
424
            esp_do_dma(s);
425
        } else if (s->dma_counter != 0 && s->ti_size <= 0) {
426
            /* If this was the last part of a DMA transfer then the
427
               completion interrupt is deferred to here.  */
428
            esp_dma_done(s);
429
        }
430 435
    }
431 436
}
432 437

  
......
725 730
}
726 731

  
727 732
static const struct SCSIBusOps esp_scsi_ops = {
733
    .transfer_data = esp_transfer_data,
728 734
    .complete = esp_command_complete,
729 735
    .cancel = esp_request_cancelled
730 736
};
b/hw/lsi53c895a.c
711 711
        return 1;
712 712
    }
713 713
}
714
 /* Callback to indicate that the SCSI layer has completed a transfer.  */
715
static void lsi_command_complete(SCSIRequest *req, int reason, uint32_t arg)
714

  
715
 /* Callback to indicate that the SCSI layer has completed a command.  */
716
static void lsi_command_complete(SCSIRequest *req, uint32_t arg)
716 717
{
717 718
    LSIState *s = DO_UPCAST(LSIState, dev.qdev, req->bus->qbus.parent);
718 719
    int out;
719 720

  
720 721
    out = (s->sstat1 & PHASE_MASK) == PHASE_DO;
721
    if (reason == SCSI_REASON_DONE) {
722
        DPRINTF("Command complete status=%d\n", (int)arg);
723
        s->status = arg;
724
        s->command_complete = 2;
725
        if (s->waiting && s->dbc != 0) {
726
            /* Raise phase mismatch for short transfers.  */
727
            lsi_bad_phase(s, out, PHASE_ST);
728
        } else {
729
            lsi_set_phase(s, PHASE_ST);
730
        }
722
    DPRINTF("Command complete status=%d\n", (int)arg);
723
    s->status = arg;
724
    s->command_complete = 2;
725
    if (s->waiting && s->dbc != 0) {
726
        /* Raise phase mismatch for short transfers.  */
727
        lsi_bad_phase(s, out, PHASE_ST);
728
    } else {
729
        lsi_set_phase(s, PHASE_ST);
730
    }
731 731

  
732
        if (s->current && req == s->current->req) {
733
            scsi_req_unref(s->current->req);
734
            qemu_free(s->current);
735
            s->current = NULL;
736
        }
737
        lsi_resume_script(s);
738
        return;
732
    if (s->current && req == s->current->req) {
733
        scsi_req_unref(s->current->req);
734
        qemu_free(s->current);
735
        s->current = NULL;
739 736
    }
737
    lsi_resume_script(s);
738
}
739

  
740
 /* Callback to indicate that the SCSI layer has completed a transfer.  */
741
static void lsi_transfer_data(SCSIRequest *req, uint32_t arg)
742
{
743
    LSIState *s = DO_UPCAST(LSIState, dev.qdev, req->bus->qbus.parent);
744
    int out;
740 745

  
741 746
    if (s->waiting == 1 || !s->current || req->tag != s->current->tag ||
742 747
        (lsi_irq_on_rsl(s) && !(s->scntl1 & LSI_SCNTL1_CON))) {
......
745 750
        }
746 751
    }
747 752

  
753
    out = (s->sstat1 & PHASE_MASK) == PHASE_DO;
754

  
748 755
    /* host adapter (re)connected */
749 756
    DPRINTF("Data ready tag=0x%x len=%d\n", req->tag, arg);
750 757
    s->current->dma_len = arg;
751 758
    s->command_complete = 1;
752
    if (!s->waiting)
753
        return;
754
    if (s->waiting == 1 || s->dbc == 0) {
755
        lsi_resume_script(s);
756
    } else {
757
        lsi_do_dma(s, out);
759
    if (s->waiting) {
760
        if (s->waiting == 1 || s->dbc == 0) {
761
            lsi_resume_script(s);
762
        } else {
763
            lsi_do_dma(s, out);
764
        }
758 765
    }
759 766
}
760 767

  
......
2239 2246
}
2240 2247

  
2241 2248
static const struct SCSIBusOps lsi_scsi_ops = {
2249
    .transfer_data = lsi_transfer_data,
2242 2250
    .complete = lsi_command_complete,
2243 2251
    .cancel = lsi_request_cancelled
2244 2252
};
b/hw/scsi-bus.c
634 634
void scsi_req_data(SCSIRequest *req, int len)
635 635
{
636 636
    trace_scsi_req_data(req->dev->id, req->lun, req->tag, len);
637
    req->bus->ops->complete(req, SCSI_REASON_DATA, len);
637
    req->bus->ops->transfer_data(req, len);
638 638
}
639 639

  
640 640
void scsi_req_print(SCSIRequest *req)
......
670 670
    assert(req->status != -1);
671 671
    scsi_req_ref(req);
672 672
    scsi_req_dequeue(req);
673
    req->bus->ops->complete(req, SCSI_REASON_DONE, req->status);
673
    req->bus->ops->complete(req, req->status);
674 674
    scsi_req_unref(req);
675 675
}
676 676

  
b/hw/scsi.h
9 9

  
10 10
#define SCSI_CMD_BUF_SIZE     16
11 11

  
12
/* scsi-disk.c */
13
enum scsi_reason {
14
    SCSI_REASON_DONE, /* Command complete.  */
15
    SCSI_REASON_DATA  /* Transfer complete, more data required.  */
16
};
17

  
18 12
typedef struct SCSIBus SCSIBus;
19 13
typedef struct SCSIBusOps SCSIBusOps;
20 14
typedef struct SCSIDevice SCSIDevice;
......
84 78
};
85 79

  
86 80
struct SCSIBusOps {
87
    void (*complete)(SCSIRequest *req, int reason, uint32_t arg);
81
    void (*transfer_data)(SCSIRequest *req, uint32_t arg);
82
    void (*complete)(SCSIRequest *req, uint32_t arg);
88 83
    void (*cancel)(SCSIRequest *req);
89 84
};
90 85

  
b/hw/spapr_vscsi.c
480 480
}
481 481

  
482 482
/* Callback to indicate that the SCSI layer has completed a transfer.  */
483
static void vscsi_command_complete(SCSIRequest *sreq, int reason, uint32_t arg)
483
static void vscsi_transfer_data(SCSIRequest *sreq, uint32_t arg)
484 484
{
485 485
    VSCSIState *s = DO_UPCAST(VSCSIState, vdev.qdev, sreq->bus->qbus.parent);
486 486
    vscsi_req *req = vscsi_find_req(s, sreq);
487 487
    uint8_t *buf;
488
    int32_t res_in = 0, res_out = 0;
489 488
    int len, rc = 0;
490 489

  
491
    dprintf("VSCSI: SCSI cmd complete, r=0x%x tag=0x%x arg=0x%x, req=%p\n",
492
            reason, sreq->tag, arg, req);
490
    dprintf("VSCSI: SCSI xfer complete tag=0x%x arg=0x%x, req=%p\n",
491
            sreq->tag, arg, req);
493 492
    if (req == NULL) {
494 493
        fprintf(stderr, "VSCSI: Can't find request for tag 0x%x\n", sreq->tag);
495 494
        return;
496 495
    }
497 496

  
498 497
    if (req->sensing) {
499
        if (reason == SCSI_REASON_DONE) {
500
            dprintf("VSCSI: Sense done !\n");
501
            vscsi_send_rsp(s, req, CHECK_CONDITION, 0, 0);
502
            vscsi_put_req(s, req);
503
        } else {
504
            uint8_t *buf = scsi_req_get_buf(sreq);
505

  
506
            len = MIN(arg, SCSI_SENSE_BUF_SIZE);
507
            dprintf("VSCSI: Sense data, %d bytes:\n", len);
508
            dprintf("       %02x  %02x  %02x  %02x  %02x  %02x  %02x  %02x\n",
509
                    buf[0], buf[1], buf[2], buf[3],
510
                    buf[4], buf[5], buf[6], buf[7]);
511
            dprintf("       %02x  %02x  %02x  %02x  %02x  %02x  %02x  %02x\n",
512
                    buf[8], buf[9], buf[10], buf[11],
513
                    buf[12], buf[13], buf[14], buf[15]);
514
            memcpy(req->sense, buf, len);
515
            req->senselen = len;
516
            scsi_req_continue(req->sreq);
517
        }
518
        return;
519
    }
520

  
521
    if (reason == SCSI_REASON_DONE) {
522
        dprintf("VSCSI: Command complete err=%d\n", arg);
523
        if (arg == 0) {
524
            /* We handle overflows, not underflows for normal commands,
525
             * but hopefully nobody cares
526
             */
527
            if (req->writing) {
528
                res_out = req->data_len;
529
            } else {
530
                res_in = req->data_len;
531
            }
532
            vscsi_send_rsp(s, req, 0, res_in, res_out);
533
        } else if (arg == CHECK_CONDITION) {
534
            vscsi_send_request_sense(s, req);
535
            return;
536
        } else {
537
            vscsi_send_rsp(s, req, arg, 0, 0);
538
        }
539
        vscsi_put_req(s, req);
498
        uint8_t *buf = scsi_req_get_buf(sreq);
499

  
500
        len = MIN(arg, SCSI_SENSE_BUF_SIZE);
501
        dprintf("VSCSI: Sense data, %d bytes:\n", len);
502
        dprintf("       %02x  %02x  %02x  %02x  %02x  %02x  %02x  %02x\n",
503
                buf[0], buf[1], buf[2], buf[3],
504
                buf[4], buf[5], buf[6], buf[7]);
505
        dprintf("       %02x  %02x  %02x  %02x  %02x  %02x  %02x  %02x\n",
506
                buf[8], buf[9], buf[10], buf[11],
507
                buf[12], buf[13], buf[14], buf[15]);
508
        memcpy(req->sense, buf, len);
509
        req->senselen = len;
510
        scsi_req_continue(req->sreq);
540 511
        return;
541 512
    }
542 513

  
......
559 530
    scsi_req_continue(sreq);
560 531
}
561 532

  
533
/* Callback to indicate that the SCSI layer has completed a transfer.  */
534
static void vscsi_command_complete(SCSIRequest *sreq, uint32_t arg)
535
{
536
    VSCSIState *s = DO_UPCAST(VSCSIState, vdev.qdev, sreq->bus->qbus.parent);
537
    vscsi_req *req = vscsi_find_req(s, sreq);
538
    int32_t res_in = 0, res_out = 0;
539

  
540
    dprintf("VSCSI: SCSI cmd complete, r=0x%x tag=0x%x arg=0x%x, req=%p\n",
541
            reason, sreq->tag, arg, req);
542
    if (req == NULL) {
543
        fprintf(stderr, "VSCSI: Can't find request for tag 0x%x\n", sreq->tag);
544
        return;
545
    }
546

  
547
    if (!req->sensing && arg == CHECK_CONDITION) {
548
        vscsi_send_request_sense(s, req);
549
        return;
550
    }
551

  
552
    if (req->sensing) {
553
        dprintf("VSCSI: Sense done !\n");
554
        arg = CHECK_CONDITION;
555
    } else {
556
        dprintf("VSCSI: Command complete err=%d\n", arg);
557
        if (arg == 0) {
558
            /* We handle overflows, not underflows for normal commands,
559
             * but hopefully nobody cares
560
             */
561
            if (req->writing) {
562
                res_out = req->data_len;
563
            } else {
564
                res_in = req->data_len;
565
            }
566
        }
567
    }
568
    vscsi_send_rsp(s, req, 0, res_in, res_out);
569
    vscsi_put_req(s, req);
570
}
571

  
562 572
static void vscsi_request_cancelled(SCSIRequest *sreq)
563 573
{
564 574
    VSCSIState *s = DO_UPCAST(VSCSIState, vdev.qdev, sreq->bus->qbus.parent);
......
916 926
}
917 927

  
918 928
static const struct SCSIBusOps vscsi_scsi_ops = {
929
    .transfer_data = vscsi_transfer_data,
919 930
    .complete = vscsi_command_complete,
920 931
    .cancel = vscsi_request_cancelled
921 932
};
b/hw/usb-msd.c
208 208
    memcpy(p->data, &csw, len);
209 209
}
210 210

  
211
static void usb_msd_command_complete(SCSIRequest *req, int reason, uint32_t arg)
211
static void usb_msd_transfer_data(SCSIRequest *req, uint32_t arg)
212 212
{
213 213
    MSDState *s = DO_UPCAST(MSDState, dev.qdev, req->bus->qbus.parent);
214 214
    USBPacket *p = s->packet;
......
216 216
    if (req->tag != s->tag) {
217 217
        fprintf(stderr, "usb-msd: Unexpected SCSI Tag 0x%x\n", req->tag);
218 218
    }
219
    if (reason == SCSI_REASON_DONE) {
220
        DPRINTF("Command complete %d\n", arg);
221
        s->residue = s->data_len;
222
        s->result = arg != 0;
223
        if (s->packet) {
224
            if (s->data_len == 0 && s->mode == USB_MSDM_DATAOUT) {
225
                /* A deferred packet with no write data remaining must be
226
                   the status read packet.  */
227
                usb_msd_send_status(s, p);
228
                s->mode = USB_MSDM_CBW;
229
            } else {
230
                if (s->data_len) {
231
                    s->data_len -= s->usb_len;
232
                    if (s->mode == USB_MSDM_DATAIN)
233
                        memset(s->usb_buf, 0, s->usb_len);
234
                    s->usb_len = 0;
235
                }
236
                if (s->data_len == 0)
237
                    s->mode = USB_MSDM_CSW;
238
            }
239
            s->packet = NULL;
240
            usb_packet_complete(&s->dev, p);
241
        } else if (s->data_len == 0) {
242
            s->mode = USB_MSDM_CSW;
243
        }
244
        scsi_req_unref(req);
245
        s->req = NULL;
246
        return;
247
    }
219

  
248 220
    assert((s->mode == USB_MSDM_DATAOUT) == (req->cmd.mode == SCSI_XFER_TO_DEV));
249 221
    s->scsi_len = arg;
250 222
    s->scsi_buf = scsi_req_get_buf(req);
......
261 233
    }
262 234
}
263 235

  
236
static void usb_msd_command_complete(SCSIRequest *req, uint32_t arg)
237
{
238
    MSDState *s = DO_UPCAST(MSDState, dev.qdev, req->bus->qbus.parent);
239
    USBPacket *p = s->packet;
240

  
241
    if (req->tag != s->tag) {
242
        fprintf(stderr, "usb-msd: Unexpected SCSI Tag 0x%x\n", req->tag);
243
    }
244
    DPRINTF("Command complete %d\n", arg);
245
    s->residue = s->data_len;
246
    s->result = arg != 0;
247
    if (s->packet) {
248
        if (s->data_len == 0 && s->mode == USB_MSDM_DATAOUT) {
249
            /* A deferred packet with no write data remaining must be
250
               the status read packet.  */
251
            usb_msd_send_status(s, p);
252
            s->mode = USB_MSDM_CBW;
253
        } else {
254
            if (s->data_len) {
255
                s->data_len -= s->usb_len;
256
                if (s->mode == USB_MSDM_DATAIN) {
257
                    memset(s->usb_buf, 0, s->usb_len);
258
                }
259
                s->usb_len = 0;
260
            }
261
            if (s->data_len == 0) {
262
                s->mode = USB_MSDM_CSW;
263
            }
264
        }
265
        s->packet = NULL;
266
        usb_packet_complete(&s->dev, p);
267
    } else if (s->data_len == 0) {
268
        s->mode = USB_MSDM_CSW;
269
    }
270
    scsi_req_unref(req);
271
    s->req = NULL;
272
}
273

  
264 274
static void usb_msd_request_cancelled(SCSIRequest *req)
265 275
{
266 276
    MSDState *s = DO_UPCAST(MSDState, dev.qdev, req->bus->qbus.parent);
......
494 504
}
495 505

  
496 506
static const struct SCSIBusOps usb_msd_scsi_ops = {
507
    .transfer_data = usb_msd_transfer_data,
497 508
    .complete = usb_msd_command_complete,
498 509
    .cancel = usb_msd_request_cancelled
499 510
};

Also available in: Unified diff