Revision afa46c46 hw/scsi-bus.c

b/hw/scsi-bus.c
7 7
#include "trace.h"
8 8

  
9 9
static char *scsibus_get_fw_dev_path(DeviceState *dev);
10
static int scsi_req_parse(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf);
10 11
static int scsi_build_sense(uint8_t *in_buf, int in_len,
11 12
                            uint8_t *buf, int len, bool fixed);
12 13

  
......
134 135
    return res;
135 136
}
136 137

  
138
/* SCSIReqOps implementation for invalid commands.  */
139

  
140
static int32_t scsi_invalid_command(SCSIRequest *req, uint8_t *buf)
141
{
142
    scsi_req_build_sense(req, SENSE_CODE(INVALID_OPCODE));
143
    scsi_req_complete(req, CHECK_CONDITION);
144
    return 0;
145
}
146

  
147
struct SCSIReqOps reqops_invalid_opcode = {
148
    .size         = sizeof(SCSIRequest),
149
    .send_command = scsi_invalid_command
150
};
151

  
137 152
SCSIRequest *scsi_req_alloc(SCSIReqOps *reqops, SCSIDevice *d, uint32_t tag,
138 153
                            uint32_t lun, void *hba_private)
139 154
{
......
157 172
                          uint8_t *buf, void *hba_private)
158 173
{
159 174
    SCSIRequest *req;
160
    req = d->info->alloc_req(d, tag, lun, hba_private);
161
    memcpy(req->cmd.buf, buf, 16);
175
    SCSICommand cmd;
176

  
177
    if (scsi_req_parse(&cmd, d, buf) != 0) {
178
        trace_scsi_req_parse_bad(d->id, lun, tag, buf[0]);
179
        req = scsi_req_alloc(&reqops_invalid_opcode, d, tag, lun, hba_private);
180
    } else {
181
        trace_scsi_req_parsed(d->id, lun, tag, buf[0],
182
                              cmd.mode, cmd.xfer);
183
        if (req->cmd.lba != -1) {
184
            trace_scsi_req_parsed_lba(d->id, lun, tag, buf[0],
185
                                      cmd.lba);
186
        }
187
        req = d->info->alloc_req(d, tag, lun, hba_private);
188
    }
189

  
190
    req->cmd = cmd;
162 191
    return req;
163 192
}
164 193

  
......
424 453
    return lba;
425 454
}
426 455

  
427
int scsi_req_parse(SCSIRequest *req, uint8_t *buf)
456
int scsi_req_parse(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf)
428 457
{
429 458
    int rc;
430 459

  
431
    if (req->dev->type == TYPE_TAPE) {
432
        rc = scsi_req_stream_length(&req->cmd, req->dev, buf);
460
    if (dev->type == TYPE_TAPE) {
461
        rc = scsi_req_stream_length(cmd, dev, buf);
433 462
    } else {
434
        rc = scsi_req_length(&req->cmd, req->dev, buf);
463
        rc = scsi_req_length(cmd, dev, buf);
435 464
    }
436 465
    if (rc != 0)
437 466
        return rc;
438 467

  
439
    assert(buf == req->cmd.buf);
440
    scsi_cmd_xfer_mode(&req->cmd);
441
    req->cmd.lba = scsi_cmd_lba(&req->cmd);
442
    trace_scsi_req_parsed(req->dev->id, req->lun, req->tag, buf[0],
443
                          req->cmd.mode, req->cmd.xfer);
444
    if (req->cmd.lba != -1) {
445
        trace_scsi_req_parsed_lba(req->dev->id, req->lun, req->tag, buf[0],
446
                              req->cmd.lba);
447
    }
468
    memcpy(cmd->buf, buf, cmd->len);
469
    scsi_cmd_xfer_mode(cmd);
470
    cmd->lba = scsi_cmd_lba(cmd);
448 471
    return 0;
449 472
}
450 473

  

Also available in: Unified diff