From patchwork Fri Sep 21 14:52:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 185781 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DFCB92C007D for ; Sat, 22 Sep 2012 01:23:50 +1000 (EST) Received: from localhost ([::1]:60056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TF4cd-00082K-HA for incoming@patchwork.ozlabs.org; Fri, 21 Sep 2012 10:54:27 -0400 Received: from eggs.gnu.org ([208.118.235.92]:58744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TF4bm-00064c-GU for qemu-devel@nongnu.org; Fri, 21 Sep 2012 10:53:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TF4bg-00006z-JA for qemu-devel@nongnu.org; Fri, 21 Sep 2012 10:53:34 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:56278) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TF4bg-0008Uh-Cy for qemu-devel@nongnu.org; Fri, 21 Sep 2012 10:53:28 -0400 Received: by mail-pb0-f45.google.com with SMTP id rp12so7853400pbb.4 for ; Fri, 21 Sep 2012 07:53:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=nGa7znVArBdfJbqH+HaQOiIDzkF946jJT2ezVab5pxo=; b=GjUuqQeBlW3UCNXxwxO6tf/N2TmaHrQErMnyT6caDHRPKZAz3NP9ulEVFgx46rusxr gfSUIF7vbWZ1tW0Gt4tTGVyL0WWLmbUTGcM4sMpoAh7hNCsrmVmKTkpmC4+MlvYIJ9X1 ySf/oyptjHpjqnt1VbtHU5DUJpqiObY+Vlh4IgATuKwCy/rx7UtLxwkhhzJwpnOiKsDa ncD8ft5l439cjkflBM5lN9lDjeodCwyvrQMGxJqLiRcvG4rZx4cNHDIXQFBZ7iwIb7ah YU/TlAdrxzbCfaaTOJylU3n+mRkMtRekrnqIOljGO5bgh+G2SnxDRPrTr5UsTAExqUbI UDWw== Received: by 10.68.132.69 with SMTP id os5mr16289736pbb.94.1348239207977; Fri, 21 Sep 2012 07:53:27 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-169-1.ip50.fastwebnet.it. [93.34.169.1]) by mx.google.com with ESMTPS id tw5sm5236070pbc.48.2012.09.21.07.53.25 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 21 Sep 2012 07:53:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2012 16:52:47 +0200 Message-Id: <1348239169-25040-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1348239169-25040-1-git-send-email-pbonzini@redhat.com> References: <1348239169-25040-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 5/7] scsi: introduce scsi_cdb_length and scsi_data_cdb_length X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Paolo Bonzini --- hw/scsi-bus.c | 23 ++++++++++++++++++----- hw/scsi.h | 2 ++ 2 file modificati, 20 inserzioni(+), 5 rimozioni(-) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 4981a02..058d3b2 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -801,26 +801,39 @@ static int ata_passthrough_16_xfer_size(SCSIDevice *dev, uint8_t *buf) return xfer * unit; } -static int scsi_req_length(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf) +uint32_t scsi_data_cdb_length(uint8_t *buf) +{ + if ((buf[0] >> 5) == 0 && buf[4] == 0) { + return 256; + } else { + return scsi_cdb_length(buf); + } +} + +uint32_t scsi_cdb_length(uint8_t *buf) { switch (buf[0] >> 5) { case 0: - cmd->xfer = buf[4]; + return buf[4]; break; case 1: case 2: - cmd->xfer = lduw_be_p(&buf[7]); + return lduw_be_p(&buf[7]); break; case 4: - cmd->xfer = ldl_be_p(&buf[10]) & 0xffffffffULL; + return ldl_be_p(&buf[10]) & 0xffffffffULL; break; case 5: - cmd->xfer = ldl_be_p(&buf[6]) & 0xffffffffULL; + return ldl_be_p(&buf[6]) & 0xffffffffULL; break; default: return -1; } +} +static int scsi_req_length(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf) +{ + cmd->xfer = scsi_cdb_length(buf); switch (buf[0]) { case TEST_UNIT_READY: case REWIND: diff --git a/hw/scsi.h b/hw/scsi.h index 1aeee46..b8f7357 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -218,6 +218,8 @@ extern const struct SCSISense sense_code_WRITE_PROTECTED; #define SENSE_CODE(x) sense_code_ ## x +uint32_t scsi_data_cdb_length(uint8_t *buf); +uint32_t scsi_cdb_length(uint8_t *buf); int scsi_sense_valid(SCSISense sense); int scsi_build_sense(uint8_t *in_buf, int in_len, uint8_t *buf, int len, bool fixed);