From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [62.140.7.102]) by mx.groups.io with SMTP id smtpd.web12.13914.1593576352944997711 for ; Tue, 30 Jun 2020 21:05:53 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: suse.com, ip: 62.140.7.102, mailfrom: glin@suse.com) Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-am5eur02lp2050.outbound.protection.outlook.com [104.47.4.50]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-6-82iUyI--NGqeVXFCpAtiNQ-1; Wed, 01 Jul 2020 06:05:50 +0200 X-MC-Unique: 82iUyI--NGqeVXFCpAtiNQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KnFn+YVXWe+sty+iCtWAeVnGJd6YU/CBH/MgxUVnc1pe3r7P8bMfgJnOXmVBIlowMPTI+JpN1Xk0Gf1XuHa6cPLttrwKpZWZs2o7Ax9sXa80r4CaeVQrvZWB+Ls3qxgWeIV1FkvaeCblhGMZja8gMTjWFyCAiLsv8vIJn7JH8Fq+m7ZG0T5NUd0zzDfWsSQsfgIwmIKlGvSi1sGfYzD4wYKpPIuJw6BW8aY36KBeKXQjD2V05OHIFFMFn507v4mhzt6oKDelJoJWkXa3Zxd9UkxknYUafJDhkoY8ZDqK0t6ESSV6M8Z3V7Kljwjel8hVSNU8L9IsA3wdrr4CmqDajA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dm4Ebx7xHlsFgsG50FFWeSMRfZayp/OIZ4PGncQYlcg=; b=GDHIb9QRhnDzupxEy/JROVwc0OVU8NRi5gYiK+0hOksmFEm6XHQa+ZbZkEc7B34hkgm7ojlzizX5pitWOTIFlyhebsXH64DfnvSAwzO+fRUvPDnP2OhpMobsnzIZ4yzLxs0M25DEFGxTZ0LEqP8gR+5VmKn3HS+Iwt6f7+oB+j25M29bGyNR60sx9wvtAq8qkiEAypthQTwQ/l9aGYraCPiRowF67ncj+MukefKZsMVQDMRJ+kXkAnLG23p8r6QO0Naf6Zn7mhfSOkwY0FSDCK2MkneZdkvrqnoStoIxwD+m8c4Nwvnd69N/h0lqzoVxlmFw5nWsaKciU2h/Nj6Nog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=suse.com; Received: from AM0PR0402MB3809.eurprd04.prod.outlook.com (2603:10a6:208:10::30) by AM0PR04MB4481.eurprd04.prod.outlook.com (2603:10a6:208:70::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.21; Wed, 1 Jul 2020 04:05:49 +0000 Received: from AM0PR0402MB3809.eurprd04.prod.outlook.com ([fe80::8806:715f:1409:8c6b]) by AM0PR0402MB3809.eurprd04.prod.outlook.com ([fe80::8806:715f:1409:8c6b%7]) with mapi id 15.20.3153.021; Wed, 1 Jul 2020 04:05:49 +0000 From: "Gary Lin" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [PATCH 10/11] OvmfPkg/LsiScsiDxe: Process the SCSI Request Packet Date: Wed, 1 Jul 2020 12:04:47 +0800 Message-Id: <20200701040448.14871-11-glin@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200701040448.14871-1-glin@suse.com> References: <20200701040448.14871-1-glin@suse.com> X-ClientProxiedBy: AM0PR10CA0047.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::27) To AM0PR0402MB3809.eurprd04.prod.outlook.com (2603:10a6:208:10::30) Return-Path: glin@suse.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from GaryWorkstation.suse.cz (60.251.47.115) by AM0PR10CA0047.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.21 via Frontend Transport; Wed, 1 Jul 2020 04:05:47 +0000 X-Mailer: git-send-email 2.25.1 X-Originating-IP: [60.251.47.115] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 30f8d538-f156-4648-6b2a-08d81d7409d6 X-MS-TrafficTypeDiagnostic: AM0PR04MB4481: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-Forefront-PRVS: 04519BA941 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YgiRnOqqU1J+LpFD/tQaAKQQ3/xYMGA67/7VqEbmWhq4jWhllb7XW8S1YlPMxY5wsbEhu0LeTTQIECGrZNs5yh9iTYwZWmI0akfb0l3157eBQF4OD0L0eAlgU7EsJXElmqxDRVyk0Fb7HLnJGiW91O6jgfb2NAN2uBYfk5vXE2HFtTqjlqdKpj9qIgThdru3pAbq19aeG6j7hbB1D9wISwNjVXlH3MLE8JPk6YHkrFGsW1Hn7ca5mKDF9QncJ4BhzUpxtksekqv6GwhNN1mfvhNOtud6ZgqokbOEJH2rVS2TvG0PjwXHPR8gRRdMg+aPOro9HI2b8E/2YaUcAgo44g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR0402MB3809.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(366004)(136003)(376002)(39860400002)(396003)(346002)(2616005)(83380400001)(26005)(54906003)(4326008)(16526019)(1076003)(956004)(86362001)(6506007)(186003)(66476007)(66556008)(8936002)(6486002)(52116002)(6916009)(5660300002)(30864003)(8676002)(36756003)(66946007)(55236004)(316002)(6512007)(478600001)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: T+iN8Qxj6zmAB9FY+N4JS4gFfXMrSEZnVBGUu27d6wlyjJ6/8P5L7RtR3uuaxvazQ/REXN02ZJQuUsu9EoHI1DFmsQLZ0j08EViVECJwvXNDqRgxPiPfZ9HAQVJNtP3yUQs7blTbY+gCQ2rAbrhM7q0QDoDD3KarU0+r7ANwK9KU1G6OJYbDn4DIAGvBF0e4urTNfcwmcZEhOpUvbzkiN/Cbgfq4bK8gAtueUo7LtukAAtWcRq2GeQ2UsfEFoec1Md2DWhB8dBpJdyKahoSMhdcqzVmtYOFbHBDUJY9XmijGKDL/tAhCMwyJgqWfjzAAdDyaLe0Qr0lG/hXkrmDBpLiNaSOG9C5YubLt2G5Px//hunRlcGhq8ArxjbJ3w57JGw45MFJK8TkTyeuBFWYVUZf2OeZRDQq+kgztWEzaJLUDn/h25DQF+EQ1BhwcbXaU17ajUCGEPwFnp/n88H2mQquSbHFmdGDXRMRbzBV9Ch8= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30f8d538-f156-4648-6b2a-08d81d7409d6 X-MS-Exchange-CrossTenant-AuthSource: AM0PR0402MB3809.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jul 2020 04:05:49.4932 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xagIlEigetNUUh9dkjjkWhStP5txEE+jAXvolfFtz0RAdXcbV/G+/AtHh2eoTIza X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4481 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain This is the second part of LsiScsiPassThru(). LsiScsiProcessRequest() is added to translate the SCSI Request Packet into the LSI 53C895A commands. This function utilizes the so-called Script buffer to transmit a series of commands to the chip and then polls the DMA Status (DSTAT) register until the Scripts Interrupt Instruction Received (SIR) bit sets. Once the script is done, the SCSI Request Packet will be modified to reflect the result of the script. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Gary Lin --- OvmfPkg/Include/IndustryStandard/LsiScsi.h | 39 +++ OvmfPkg/LsiScsiDxe/LsiScsi.c | 308 +++++++++++++++++++++ OvmfPkg/LsiScsiDxe/LsiScsi.h | 21 ++ OvmfPkg/LsiScsiDxe/LsiScsiDxe.inf | 3 + OvmfPkg/OvmfPkg.dec | 3 + 5 files changed, 374 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/LsiScsi.h b/OvmfPkg/Include/I= ndustryStandard/LsiScsi.h index 60e527f1c6a7..cbf049c18310 100644 --- a/OvmfPkg/Include/IndustryStandard/LsiScsi.h +++ b/OvmfPkg/Include/IndustryStandard/LsiScsi.h @@ -26,6 +26,18 @@ #define LSI_REG_SIST0 0x42=0D #define LSI_REG_SIST1 0x43=0D =0D +//=0D +// The status bits for DMA Status (DSTAT)=0D +//=0D +#define LSI_DSTAT_IID 0x01=0D +#define LSI_DSTAT_R 0x02=0D +#define LSI_DSTAT_SIR 0x04=0D +#define LSI_DSTAT_SSI 0x08=0D +#define LSI_DSTAT_ABRT 0x10=0D +#define LSI_DSTAT_BF 0x20=0D +#define LSI_DSTAT_MDPE 0x40=0D +#define LSI_DSTAT_DFE 0x80=0D +=0D //=0D // The status bits for Interrupt Status Zero (ISTAT0)=0D //=0D @@ -38,4 +50,31 @@ #define LSI_ISTAT0_SRST 0x40=0D #define LSI_ISTAT0_ABRT 0x80=0D =0D +//=0D +// LSI 53C895A Script Instructions=0D +//=0D +#define LSI_INS_TYPE_BLK 0x00000000=0D +#define LSI_INS_TYPE_IO 0x40000000=0D +#define LSI_INS_TYPE_TC 0x80000000=0D +=0D +#define LSI_INS_BLK_SCSIP_DAT_OUT 0x00000000=0D +#define LSI_INS_BLK_SCSIP_DAT_IN 0x01000000=0D +#define LSI_INS_BLK_SCSIP_CMD 0x02000000=0D +#define LSI_INS_BLK_SCSIP_STAT 0x03000000=0D +#define LSI_INS_BLK_SCSIP_MSG_OUT 0x06000000=0D +#define LSI_INS_BLK_SCSIP_MSG_IN 0x07000000=0D +=0D +#define LSI_INS_IO_OPC_SEL 0x00000000=0D +#define LSI_INS_IO_OPC_WAIT_RESEL 0x10000000=0D +=0D +#define LSI_INS_TC_CP 0x00020000=0D +#define LSI_INS_TC_JMP 0x00080000=0D +#define LSI_INS_TC_RA 0x00800000=0D +=0D +#define LSI_INS_TC_OPC_JMP 0x00000000=0D +#define LSI_INS_TC_OPC_INT 0x18000000=0D +=0D +#define LSI_INS_TC_SCSIP_DAT_OUT 0x00000000=0D +#define LSI_INS_TC_SCSIP_MSG_IN 0x07000000=0D +=0D #endif // _LSI_SCSI_H_=0D diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.c b/OvmfPkg/LsiScsiDxe/LsiScsi.c index 1bcebd92e455..090d7df15b34 100644 --- a/OvmfPkg/LsiScsiDxe/LsiScsi.c +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.c @@ -43,6 +43,42 @@ Out8 ( );=0D }=0D =0D +STATIC=0D +EFI_STATUS=0D +Out32 (=0D + IN LSI_SCSI_DEV *Dev,=0D + IN UINT32 Addr,=0D + IN UINT32 Data=0D + )=0D +{=0D + return Dev->PciIo->Io.Write (=0D + Dev->PciIo,=0D + EfiPciIoWidthUint32,=0D + PCI_BAR_IDX0,=0D + Addr,=0D + 1,=0D + &Data=0D + );=0D +}=0D +=0D +STATIC=0D +EFI_STATUS=0D +In8 (=0D + IN LSI_SCSI_DEV *Dev,=0D + IN UINT32 Addr,=0D + OUT UINT8 *Data=0D + )=0D +{=0D + return Dev->PciIo->Io.Read (=0D + Dev->PciIo,=0D + EfiPciIoWidthUint8,=0D + PCI_BAR_IDX0,=0D + Addr,=0D + 1,=0D + Data=0D + );=0D +}=0D +=0D STATIC=0D EFI_STATUS=0D LsiScsiReset (=0D @@ -141,6 +177,272 @@ LsiScsiCheckRequest ( return EFI_SUCCESS;=0D }=0D =0D +/**=0D +=0D + Interpret the request packet from the Extended SCSI Pass Thru Protocol a= nd=0D + compose the script to submit the command and data to the contorller.=0D +=0D + @param[in] Dev The LSI 53C895A SCSI device the packet targets.= =0D +=0D + @param[in] Target The SCSI target controlled by the LSI 53C895A SC= SI=0D + device.=0D +=0D + @param[in] Lun The Logical Unit Number under the SCSI target.=0D +=0D + @param[in out] Packet The Extended SCSI Pass Thru Protocol packet.=0D +=0D +=0D + @retval EFI_SUCCESS The Extended SCSI Pass Thru Protocol packet was val= id.=0D +=0D + @return Otherwise, invalid or unsupported parameters were=0D + detected. Status codes are meant for direct forward= ing=0D + by the EFI_EXT_SCSI_PASS_THRU_PROTOCOL.PassThru()=0D + implementation.=0D +=0D + **/=0D +STATIC=0D +EFI_STATUS=0D +LsiScsiProcessRequest (=0D + IN LSI_SCSI_DEV *Dev,=0D + IN UINT8 Target,=0D + IN UINT64 Lun,=0D + IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINT32 *Script;=0D + UINT8 *Cdb;=0D + UINT8 *MsgOut;=0D + UINT8 *MsgIn;=0D + UINT8 *ScsiStatus;=0D + UINT8 *Data;=0D + UINT8 DStat;=0D + UINT8 SIst0;=0D + UINT8 SIst1;=0D +=0D + Script =3D Dev->Dma->Script;=0D + Cdb =3D Dev->Dma->Cdb;=0D + Data =3D Dev->Dma->Data;=0D + MsgIn =3D Dev->Dma->MsgIn;=0D + MsgOut =3D &Dev->Dma->MsgOut;=0D + ScsiStatus =3D &Dev->Dma->Status;=0D +=0D + *ScsiStatus =3D 0xFF;=0D +=0D + SetMem (Cdb, sizeof Dev->Dma->Cdb, 0x00);=0D + CopyMem (Cdb, Packet->Cdb, Packet->CdbLength);=0D +=0D + //=0D + // Clean up the DMA buffer for the script.=0D + //=0D + SetMem (Script, sizeof Dev->Dma->Script, 0x00);=0D +=0D + //=0D + // Compose the script to transfer data between the host and the device.= =0D + //=0D + // Reference:=0D + // LSI53C895A PCI to Ultra2 SCSI Controller Version 2.2=0D + // - Chapter 5 SCSI SCRIPT Instruction Set=0D + //=0D + // All instructions used here consist of 2 32bit words. The first word=0D + // contains the command to execute. The second word is loaded into the=0D + // DMA SCRIPTS Pointer Save (DSPS) register as either the DMA address=0D + // for data transmission or the address/offset for the jump command.=0D + // Some commands, such as the selection of the target, don't need to=0D + // transfer data through DMA or jump to another instruction, then DSPS=0D + // has to be zero.=0D + //=0D + // There are 3 major parts in this script. The first part (1~3) contains= =0D + // the instructions to select target and LUN and send the SCSI command=0D + // from the request packet. The second part (4~7) is to handle the=0D + // potential disconnection and prepare for the data transmission. The=0D + // instructions in the third part (8~10) transmit the given data and=0D + // collect the result. Instruction 11 raises the interrupt and marks the= =0D + // end of the script.=0D + //=0D +=0D + //=0D + // 1. Select target.=0D + //=0D + *Script++ =3D LSI_INS_TYPE_IO | LSI_INS_IO_OPC_SEL | (UINT32)Target << 1= 6;=0D + *Script++ =3D 0x00000000;=0D +=0D + //=0D + // 2. Select LUN.=0D + //=0D + *MsgOut =3D 0x80 | (UINT8) Lun; // 0x80: Identify bit=0D + *Script++ =3D LSI_INS_TYPE_BLK | LSI_INS_BLK_SCSIP_MSG_OUT | \=0D + sizeof Dev->Dma->MsgOut;=0D + *Script++ =3D LSI_SCSI_DMA_ADDR_LOW (Dev, MsgOut);=0D +=0D + //=0D + // 3. Send the SCSI Command.=0D + //=0D + *Script++ =3D LSI_INS_TYPE_BLK | LSI_INS_BLK_SCSIP_CMD | \=0D + sizeof Dev->Dma->Cdb;=0D + *Script++ =3D LSI_SCSI_DMA_ADDR_LOW (Dev, Cdb);=0D +=0D + //=0D + // 4. Check whether the current SCSI phase is "Message In" or not=0D + // and jump to 8 if it is.=0D + //=0D + *Script++ =3D LSI_INS_TYPE_TC | LSI_INS_TC_OPC_JMP | \=0D + LSI_INS_TC_SCSIP_MSG_IN | LSI_INS_TC_RA | \=0D + LSI_INS_TC_CP;=0D + *Script++ =3D 0x00000018;=0D +=0D + //=0D + // 5. Read "Message" from the initiator to trigger reselect.=0D + //=0D + *Script++ =3D LSI_INS_TYPE_BLK | LSI_INS_BLK_SCSIP_MSG_IN | \=0D + sizeof Dev->Dma->MsgIn;=0D + *Script++ =3D LSI_SCSI_DMA_ADDR_LOW (Dev, MsgIn);=0D +=0D + //=0D + // 6. Wait reselect.=0D + //=0D + *Script++ =3D LSI_INS_TYPE_IO | LSI_INS_IO_OPC_WAIT_RESEL;=0D + *Script++ =3D 0x00000000;=0D +=0D + //=0D + // 7. Read "Message" from the initiator again=0D + //=0D + *Script++ =3D LSI_INS_TYPE_BLK | LSI_INS_BLK_SCSIP_MSG_IN | \=0D + sizeof Dev->Dma->MsgIn;=0D + *Script++ =3D LSI_SCSI_DMA_ADDR_LOW (Dev, MsgIn);=0D +=0D + //=0D + // 8. Set the DMA command for the read/write operations.=0D + //=0D + if (Packet->DataDirection =3D=3D EFI_EXT_SCSI_DATA_DIRECTION_READ &&=0D + Packet->InTransferLength > 0) {=0D + *Script++ =3D LSI_INS_TYPE_BLK | LSI_INS_BLK_SCSIP_DAT_IN | \=0D + Packet->InTransferLength;=0D + *Script++ =3D LSI_SCSI_DMA_ADDR_LOW (Dev, Data);=0D + } else if (Packet->DataDirection =3D=3D EFI_EXT_SCSI_DATA_DIRECTION_WRIT= E &&=0D + Packet->OutTransferLength > 0) {=0D + // LsiScsiCheckRequest() guarantees that OutTransferLength is no=0D + // larger than sizeof Dev->Dma->Data, so we can safely copy the=0D + // the data to Dev->Dma->Data.=0D + CopyMem (Data, Packet->OutDataBuffer, Packet->OutTransferLength);=0D + *Script++ =3D LSI_INS_TYPE_BLK | LSI_INS_BLK_SCSIP_DAT_OUT | \=0D + Packet->OutTransferLength;=0D + *Script++ =3D LSI_SCSI_DMA_ADDR_LOW (Dev, Data);=0D + }=0D +=0D + //=0D + // 9. Get the SCSI status.=0D + //=0D + *Script++ =3D LSI_INS_TYPE_BLK | LSI_INS_BLK_SCSIP_STAT | \=0D + sizeof Dev->Dma->Status;=0D + *Script++ =3D LSI_SCSI_DMA_ADDR_LOW (Dev, Status);=0D +=0D + //=0D + // 10. Get the SCSI message.=0D + //=0D + *Script++ =3D LSI_INS_TYPE_BLK | LSI_INS_BLK_SCSIP_MSG_IN | \=0D + sizeof Dev->Dma->MsgIn;=0D + *Script++ =3D LSI_SCSI_DMA_ADDR_LOW (Dev, MsgIn);=0D +=0D + //=0D + // 11. Raise the interrupt to end the script.=0D + //=0D + *Script++ =3D LSI_INS_TYPE_TC | LSI_INS_TC_OPC_INT | \=0D + LSI_INS_TC_SCSIP_DAT_OUT | LSI_INS_TC_JMP;=0D + *Script++ =3D 0x00000000;=0D +=0D + //=0D + // Make sure the size of the script doesn't exceed the buffer.=0D + //=0D + ASSERT (Script < Dev->Dma->Script + sizeof Dev->Dma->Script);=0D +=0D + //=0D + // The controller starts to execute the script once the DMA Script=0D + // Pointer (DSP) register is set.=0D + //=0D + Status =3D Out32 (Dev, LSI_REG_DSP, LSI_SCSI_DMA_ADDR_LOW(Dev, Script));= =0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + //=0D + // Poll the device registers (DSTAT, SIST0, and SIST1) until the SIR=0D + // bit sets.=0D + //=0D + for(;;) {=0D + Status =3D In8 (Dev, LSI_REG_DSTAT, &DStat);=0D + if (EFI_ERROR (Status)) {=0D + goto Error;=0D + }=0D + Status =3D In8 (Dev, LSI_REG_SIST0, &SIst0);=0D + if (EFI_ERROR (Status)) {=0D + goto Error;=0D + }=0D + Status =3D In8 (Dev, LSI_REG_SIST1, &SIst1);=0D + if (EFI_ERROR (Status)) {=0D + goto Error;=0D + }=0D +=0D + if (SIst0 !=3D 0 || SIst1 !=3D 0) {=0D + goto Error;=0D + }=0D +=0D + //=0D + // Check the SIR (SCRIPTS Interrupt Instruction Received) bit.=0D + //=0D + if (DStat & LSI_DSTAT_SIR) {=0D + break;=0D + }=0D +=0D + gBS->Stall (Dev->StallPerPollUsec);=0D + }=0D +=0D + //=0D + // Check if everything is good.=0D + // SCSI Message Code 0x00: COMMAND COMPLETE=0D + // SCSI Status Code 0x00: Good=0D + //=0D + if (MsgIn[0] =3D=3D 0 && *ScsiStatus =3D=3D 0) {=0D + //=0D + // Copy Data to InDataBuffer if necessary.=0D + //=0D + if (Packet->DataDirection =3D=3D EFI_EXT_SCSI_DATA_DIRECTION_READ) {=0D + CopyMem (Packet->InDataBuffer, Data, Packet->InTransferLength);=0D + }=0D +=0D + //=0D + // The controller doesn't return sense data when replying "TEST UNIT R= EADY",=0D + // so we have to set SenseDataLength to 0 to notify ScsiIo to issue=0D + // "REQUEST SENSE" for the sense data.=0D + //=0D + if (Cdb[0] =3D=3D 0x00) {=0D + Packet->SenseDataLength =3D 0;=0D + }=0D + Packet->HostAdapterStatus =3D EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OK;=0D + Packet->TargetStatus =3D EFI_EXT_SCSI_STATUS_TARGET_GOOD;=0D +=0D + return EFI_SUCCESS;=0D + }=0D +=0D +Error:=0D + DEBUG((DEBUG_VERBOSE, "%a: dstat: %02X, sist0: %02X, sist1: %02X\n",=0D + __FUNCTION__, DStat, SIst0, SIst1));=0D + //=0D + // Update the request packet to reflect the status.=0D + //=0D + if (*ScsiStatus !=3D 0xFF) {=0D + Packet->TargetStatus =3D *ScsiStatus;=0D + } else {=0D + Packet->TargetStatus =3D EFI_EXT_SCSI_STATUS_TARGET_TASK_ABORTED;=0D + }=0D + Packet->HostAdapterStatus =3D EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OTHER;=0D + Packet->InTransferLength =3D 0;=0D + Packet->OutTransferLength =3D 0;=0D + Packet->SenseDataLength =3D 0;=0D +=0D + return EFI_DEVICE_ERROR;=0D +}=0D +=0D //=0D // The next seven functions implement EFI_EXT_SCSI_PASS_THRU_PROTOCOL=0D // for the LSI 53C895A SCSI Controller. Refer to UEFI Spec 2.3.1 + Errata = C,=0D @@ -168,6 +470,11 @@ LsiScsiPassThru ( return Status;=0D }=0D =0D + Status =3D LsiScsiProcessRequest (Dev, *Target, Lun, Packet);=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D return EFI_SUCCESS;=0D }=0D =0D @@ -469,6 +776,7 @@ LsiScsiControllerStart ( =0D Dev->MaxTarget =3D PcdGet8 (PcdLsiScsiMaxTargetLimit);=0D Dev->MaxLun =3D PcdGet8 (PcdLsiScsiMaxLunLimit);=0D + Dev->StallPerPollUsec =3D PcdGet32 (PcdLsiScsiStallPerPollUsec);=0D =0D Status =3D gBS->OpenProtocol (=0D ControllerHandle,=0D diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.h b/OvmfPkg/LsiScsiDxe/LsiScsi.h index 9272eb7506c7..1a16ef9f7795 100644 --- a/OvmfPkg/LsiScsiDxe/LsiScsi.h +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.h @@ -13,6 +13,11 @@ #define _LSI_SCSI_DXE_H_=0D =0D typedef struct {=0D + //=0D + // Allocate 32 UINT32 entries for the script and it's sufficient for=0D + // 16 instructions.=0D + //=0D + UINT32 Script[32];=0D //=0D // The max size of CDB is 32.=0D //=0D @@ -21,6 +26,18 @@ typedef struct { // Allocate 64KB for read/write buffer.=0D //=0D UINT8 Data[0x10000];=0D + //=0D + // For SCSI Message In phase=0D + //=0D + UINT8 MsgIn[2];=0D + //=0D + // For SCSI Message Out phase=0D + //=0D + UINT8 MsgOut;=0D + //=0D + // For SCSI Status phase=0D + //=0D + UINT8 Status;=0D } LSI_SCSI_DMA_BUFFER;=0D =0D typedef struct {=0D @@ -30,6 +47,7 @@ typedef struct { EFI_PCI_IO_PROTOCOL *PciIo;=0D UINT8 MaxTarget;=0D UINT8 MaxLun;=0D + UINT32 StallPerPollUsec;=0D LSI_SCSI_DMA_BUFFER *Dma;=0D EFI_PHYSICAL_ADDRESS DmaPhysical;=0D VOID *DmaMapping;=0D @@ -42,6 +60,9 @@ typedef struct { #define LSI_SCSI_FROM_PASS_THRU(PassThruPtr) \=0D CR (PassThruPtr, LSI_SCSI_DEV, PassThru, LSI_SCSI_DEV_SIGNATURE)=0D =0D +#define LSI_SCSI_DMA_ADDR_LOW(Dev, MemberName) \=0D + ((UINT32)(Dev->DmaPhysical + OFFSET_OF (LSI_SCSI_DMA_BUFFER, MemberName)= ))=0D +=0D =0D //=0D // Probe, start and stop functions of this driver, called by the DXE core = for=0D diff --git a/OvmfPkg/LsiScsiDxe/LsiScsiDxe.inf b/OvmfPkg/LsiScsiDxe/LsiScsi= Dxe.inf index 68844c6772e3..cbd7294573ac 100644 --- a/OvmfPkg/LsiScsiDxe/LsiScsiDxe.inf +++ b/OvmfPkg/LsiScsiDxe/LsiScsiDxe.inf @@ -41,3 +41,6 @@ [Protocols] [FixedPcd]=0D gUefiOvmfPkgTokenSpaceGuid.PcdLsiScsiMaxTargetLimit ## CONSUMES=0D gUefiOvmfPkgTokenSpaceGuid.PcdLsiScsiMaxLunLimit ## CONSUMES=0D +=0D +[Pcd]=0D + gUefiOvmfPkgTokenSpaceGuid.PcdLsiScsiStallPerPollUsec ## CONSUMES=0D diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index ae7d1d648d22..57e418d4b8a9 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -179,6 +179,9 @@ [PcdsFixedAtBuild] gUefiOvmfPkgTokenSpaceGuid.PcdLsiScsiMaxTargetLimit|7|UINT8|0x3b=0D gUefiOvmfPkgTokenSpaceGuid.PcdLsiScsiMaxLunLimit|0|UINT8|0x3c=0D =0D + ## Microseconds to stall between polling for LsiScsi request result=0D + gUefiOvmfPkgTokenSpaceGuid.PcdLsiScsiStallPerPollUsec|5|UINT32|0x3d=0D +=0D gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageEventLogBase|0x0|UINT32|= 0x8=0D gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageEventLogSize|0x0|UINT32|= 0x9=0D gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize|0x0|UINT32|0xa=0D --=20 2.25.1