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.web11.10947.1594885614924672466 for ; Thu, 16 Jul 2020 00:46:55 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@suse.com header.s=mimecast20200619 header.b=PKCylINm; spf=pass (domain: suse.com, ip: 62.140.7.102, mailfrom: glin@suse.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1594885613; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RL6DwM1EBLMejf1O+F/HdcvvEXpi5z64ZoCi/26UAu0=; b=PKCylINmrjjqiW+yxfxif3lOqT277Zwkxs0xYxypOlevzOX3WbZFf0W72UBXQa84rTfcSZ dP55HBjGy9niyzQbNyWv/78H2e0E+4mODidwCL/kVKTEy6DwFdYJVhE5NlP2yPjxOWVkdm UkYlN04PkbHUf8SmNw5QtuS7T+rmymk= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2172.outbound.protection.outlook.com [104.47.17.172]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-4-yBmLBLrNNg6EKq3UTECeoQ-1; Thu, 16 Jul 2020 09:46:51 +0200 X-MC-Unique: yBmLBLrNNg6EKq3UTECeoQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EpMSEBYvoUwFuuA/CQ+8Pbzd9uDTGIJIEVBMXo+0D89KUzDS3cijkoIHA8APiRlkqq0YVfULcj6YvrJtcoXJeTi0GmkuUKFcbJTQFcdH3UZ9HfzvO+29o+d5jrUijSpzDqYA73TzdfGDXVEqJlALXgxQdNbUcEiF91wU38s9vETBcIpLmMHKVN/KJ6WsHjz/EUzKykNKDwdMZ/7Fj8rN7PvDAHkroM43FSl/oQuXyud7DwbouYA8MFZZasvYblb8IP2sKLh/O8ZfaWmEUwbEartiFIkBPaNS6lTsw7XKdFFGTDviOtppjIjUCproR2bwWvkiiNFN30HcnychrlMBag== 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=RL6DwM1EBLMejf1O+F/HdcvvEXpi5z64ZoCi/26UAu0=; b=Q23djh+q9AGzvRy2sZ5yZdKth4Q+jjlRuhrZuR2rGQl/9BxMFibnW+p7XA9VEfFMLna7n11zd67cdL8xPp0ikkEiSPICKDOc6AwX9ytaO1nKvovSq2lkOzJ3VUfbStkh3Zgl+133SWBhRrHQNyh6dm4Q2GkvBI09RzD7AyKTq+tGi5HpkVn7qef+5o/+6ViDsTqyS2UuyWuAtKtrtY0YiwfVOBsJuwychU8W27r7HY1P2rETQJYS/b2Ge9C3WS/jxPQ56O7cPCD8mrMJDsa3iAPG+2KUy5H/xUZmGE/PiFuRrLQtZIiup7Cv85yvOluiiUO3oeQxy3s3t5xkhaXIug== 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 AM0PR04MB4740.eurprd04.prod.outlook.com (2603:10a6:208:c8::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Thu, 16 Jul 2020 07:46:46 +0000 Received: from AM0PR0402MB3809.eurprd04.prod.outlook.com ([fe80::a14c:d441:c8a9:77ba]) by AM0PR0402MB3809.eurprd04.prod.outlook.com ([fe80::a14c:d441:c8a9:77ba%6]) with mapi id 15.20.3174.026; Thu, 16 Jul 2020 07:46:46 +0000 From: "Gary Lin" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [PATCH v2 10/12] OvmfPkg/LsiScsiDxe: Process the SCSI Request Packet Date: Thu, 16 Jul 2020 15:46:05 +0800 Message-Id: <20200716074607.18048-11-glin@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200716074607.18048-1-glin@suse.com> References: <20200716074607.18048-1-glin@suse.com> X-ClientProxiedBy: AM3PR07CA0118.eurprd07.prod.outlook.com (2603:10a6:207:7::28) 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 AM3PR07CA0118.eurprd07.prod.outlook.com (2603:10a6:207:7::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17 via Frontend Transport; Thu, 16 Jul 2020 07:46:44 +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: 5965aa87-50b2-4f83-b862-08d8295c63c6 X-MS-TrafficTypeDiagnostic: AM0PR04MB4740: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Q3KmxmmjqY3TThIcBv46zeMxD498T/PfqixMYORogK1O+mz6otuYtwC1OSfDep3/HgzIFQOZCSu1Et9RQxzprkHrZihifGIdUndPNzB+xcfiyZ7PZ6BerU8IhOOFUz2B1lRI6j3sZ/P2sy4O6XEXrdjQgZuvKcqmU7J/5fS9cgfSjuhe5o5fuvuo+YGjvW8X8w0ei4sL7eEzUW3tYooTfDHT9/Th8MVHMd366cSDjMgjgv7GvvzRAiOeRke/Ach/K5HEVB1lFQQybGEKiP3jE+6uqBtnstJQ+02xA3TY7hSUNnxIujl6+kRZyhhuclnFw8s3IDagsJf0NCEWV6P9rw== 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:(136003)(376002)(346002)(39860400002)(366004)(396003)(2616005)(956004)(26005)(478600001)(8936002)(36756003)(2906002)(54906003)(8676002)(52116002)(6916009)(316002)(6512007)(186003)(30864003)(16526019)(1076003)(6486002)(5660300002)(66556008)(66476007)(66946007)(6666004)(83380400001)(86362001)(6506007)(55236004)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: I/5Lle+fuR4LFoFnnRqfCDv8m2GYtk1n0NZXZHW6WGpgAnlCO7NRdL362sgXU2cyWqXk8TVYoqE58bzJe21hdeJi7XIEffqH7coq/WAWf4ea/uhxgl852vr8T19LJNe1vTTKYuTPgDOfJH/ul4VNuqHeC46N5pnu9HSi0+dLBStWynE/s9VZLRmrtcYzVYEGu1ZV0818AcOYmM0SjHM1GGty7JCqmjgJcqrknoFjR/p/4AI54VZqIR4eHNRXRSDlA2zXZcT6MV5ZmEsDAzvH3813Y2PMPMclnui4toeXtlpOlH2XBiwu2D/FZ593w9olwqo0N+h/R617qjKp7Ss/Ez4sqI5fxI1Y9to4ReED6wPKCCtqJz8ds4r09af/iFCIVtdOb0o6XOflGaWWG/8txLxchsm0Hqi+rwaEubqr2VPCjFQ9gu6YAaD1hUXHWEFjLCp7XHIiFMRhVRYagzzWH+KKYgyjzz1NYt+lpKQkEAU= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5965aa87-50b2-4f83-b862-08d8295c63c6 X-MS-Exchange-CrossTenant-AuthSource: AM0PR0402MB3809.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2020 07:46:46.5490 (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: lJbipWA5RgaRm6EqioazsNPtck+TJs8k83Y/46t/UVbJhi+rP94ZLko1T2ThpAHL X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4740 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. v2: - Use the BITx macros for the most of LSI_* constants - Fix a typo: contorller =3D> controller - Add SeaBIOS lsi-scsi driver as one of the references of the script - Cast the result of sizeof to UINT32 for the instructions of the script - Drop the backslashes - Replace LSI_SCSI_DMA_ADDR_LOW with LSI_SCSI_DMA_ADDR since we already removed DUAL_ADDRESS_CYCLE - Add more comments for the script - Fix the check of the script size at the end of the script - Always set SenseDataLength to 0 to avoid the caller to access SenseData - Improve the error handling in LsiScsiProcessRequest() Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Gary Lin --- OvmfPkg/Include/IndustryStandard/LsiScsi.h | 63 ++++ OvmfPkg/LsiScsiDxe/LsiScsi.c | 336 ++++++++++++++++++++- OvmfPkg/LsiScsiDxe/LsiScsi.h | 21 ++ OvmfPkg/LsiScsiDxe/LsiScsiDxe.inf | 3 + OvmfPkg/OvmfPkg.dec | 3 + 5 files changed, 425 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Include/IndustryStandard/LsiScsi.h b/OvmfPkg/Include/I= ndustryStandard/LsiScsi.h index 185e553c8eb4..9964bd40385c 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 BIT0=0D +#define LSI_DSTAT_R BIT1=0D +#define LSI_DSTAT_SIR BIT2=0D +#define LSI_DSTAT_SSI BIT3=0D +#define LSI_DSTAT_ABRT BIT4=0D +#define LSI_DSTAT_BF BIT5=0D +#define LSI_DSTAT_MDPE BIT6=0D +#define LSI_DSTAT_DFE BIT7=0D +=0D //=0D // The status bits for Interrupt Status Zero (ISTAT0)=0D //=0D @@ -38,4 +50,55 @@ #define LSI_ISTAT0_SRST BIT6=0D #define LSI_ISTAT0_ABRT BIT7=0D =0D +//=0D +// The status bits for SCSI Interrupt Status Zero (SIST0)=0D +//=0D +#define LSI_SIST0_PAR BIT0=0D +#define LSI_SIST0_RST BIT1=0D +#define LSI_SIST0_UDC BIT2=0D +#define LSI_SIST0_SGE BIT3=0D +#define LSI_SIST0_RSL BIT4=0D +#define LSI_SIST0_SEL BIT5=0D +#define LSI_SIST0_CMP BIT6=0D +#define LSI_SIST0_MA BIT7=0D +=0D +//=0D +// The status bits for SCSI Interrupt Status One (SIST1)=0D +//=0D +#define LSI_SIST1_HTH BIT0=0D +#define LSI_SIST1_GEN BIT1=0D +#define LSI_SIST1_STO BIT2=0D +#define LSI_SIST1_R3 BIT3=0D +#define LSI_SIST1_SBMC BIT4=0D +#define LSI_SIST1_R5 BIT5=0D +#define LSI_SIST1_R6 BIT6=0D +#define LSI_SIST1_R7 BIT7=0D +=0D +//=0D +// LSI 53C895A Script Instructions=0D +//=0D +#define LSI_INS_TYPE_BLK 0x00000000=0D +#define LSI_INS_TYPE_IO BIT30=0D +#define LSI_INS_TYPE_TC BIT31=0D +=0D +#define LSI_INS_BLK_SCSIP_DAT_OUT 0x00000000=0D +#define LSI_INS_BLK_SCSIP_DAT_IN BIT24=0D +#define LSI_INS_BLK_SCSIP_CMD BIT25=0D +#define LSI_INS_BLK_SCSIP_STAT (BIT24 | BIT25)=0D +#define LSI_INS_BLK_SCSIP_MSG_OUT (BIT25 | BIT26)=0D +#define LSI_INS_BLK_SCSIP_MSG_IN (BIT24 | BIT25 | BIT26)=0D +=0D +#define LSI_INS_IO_OPC_SEL 0x00000000=0D +#define LSI_INS_IO_OPC_WAIT_RESEL BIT28=0D +=0D +#define LSI_INS_TC_CP BIT17=0D +#define LSI_INS_TC_JMP BIT19=0D +#define LSI_INS_TC_RA BIT23=0D +=0D +#define LSI_INS_TC_OPC_JMP 0x00000000=0D +#define LSI_INS_TC_OPC_INT (BIT27 | BIT28)=0D +=0D +#define LSI_INS_TC_SCSIP_DAT_OUT 0x00000000=0D +#define LSI_INS_TC_SCSIP_MSG_IN (BIT24 | BIT25 | BIT26)=0D +=0D #endif // _LSI_SCSI_H_=0D diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.c b/OvmfPkg/LsiScsiDxe/LsiScsi.c index b3a88cc7119b..d5fe1d4ab3b8 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,303 @@ 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 controller.=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 + // References:=0D + // * LSI53C895A PCI to Ultra2 SCSI Controller Version 2.2=0D + // - Chapter 5 SCSI SCRIPT Instruction Set=0D + // * SEABIOS lsi-scsi driver=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 + (UINT32)sizeof Dev->Dma->MsgOut;=0D + *Script++ =3D LSI_SCSI_DMA_ADDR (Dev, MsgOut);=0D +=0D + //=0D + // 3. Send the SCSI Command.=0D + //=0D + *Script++ =3D LSI_INS_TYPE_BLK | LSI_INS_BLK_SCSIP_CMD |=0D + (UINT32)sizeof Dev->Dma->Cdb;=0D + *Script++ =3D LSI_SCSI_DMA_ADDR (Dev, Cdb);=0D +=0D + //=0D + // 4. Check whether the current SCSI phase is "Message In" or not=0D + // and jump to 7 if it is.=0D + // Note: LSI_INS_TC_RA stands for "Relative Address Mode", so the=0D + // offset 0x18 in the second word means jumping forward=0D + // 3 (0x18/8) instructions.=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 + (UINT32)sizeof Dev->Dma->MsgIn;=0D + *Script++ =3D LSI_SCSI_DMA_ADDR (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 + (UINT32)sizeof Dev->Dma->MsgIn;=0D + *Script++ =3D LSI_SCSI_DMA_ADDR (Dev, MsgIn);=0D +=0D + //=0D + // 8. Set the DMA command for the read/write operations.=0D + // Note: Some requests, e.g. "TEST UNIT READY", do not come with=0D + // allocated InDataBuffer or OutDataBuffer. We skip the DMA=0D + // data command for those requests or this script would fail=0D + // with LSI_SIST0_SGE due to the zero data length.=0D + //=0D + // LsiScsiCheckRequest() prevents both integer overflows in the command= =0D + // opcodes, and buffer overflows.=0D + //=0D + if (Packet->DataDirection =3D=3D EFI_EXT_SCSI_DATA_DIRECTION_READ &&=0D + Packet->InTransferLength > 0) {=0D + ASSERT (Packet->InTransferLength <=3D sizeof Dev->Dma->Data);=0D + *Script++ =3D LSI_INS_TYPE_BLK | LSI_INS_BLK_SCSIP_DAT_IN |=0D + Packet->InTransferLength;=0D + *Script++ =3D LSI_SCSI_DMA_ADDR (Dev, Data);=0D + } else if (Packet->DataDirection =3D=3D EFI_EXT_SCSI_DATA_DIRECTION_WRIT= E &&=0D + Packet->OutTransferLength > 0) {=0D + ASSERT (Packet->OutTransferLength <=3D sizeof 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 (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 + (UINT32)sizeof Dev->Dma->Status;=0D + *Script++ =3D LSI_SCSI_DMA_ADDR (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 + (UINT32)sizeof Dev->Dma->MsgIn;=0D + *Script++ =3D LSI_SCSI_DMA_ADDR (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 <=3D Dev->Dma->Script + ARRAY_SIZE (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 (Dev, Script));=0D + if (EFI_ERROR (Status)) {=0D + goto Error;=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 0 || *ScsiStatus !=3D 0) {=0D + goto Error;=0D + }=0D +=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 + // Always set SenseDataLength to 0.=0D + // The instructions of LSI53C895A doesn't reply sense data. Instead, it= =0D + // relies on the SCSI command, "REQUEST SENSE", to get sense data. We se= t=0D + // SenseDataLength to 0 to notify ScsiDiskDxe that there is no sense dat= a=0D + // written even if this request is processed successfully, so that It wi= ll=0D + // issue "REQUEST SENSE" later to retrieve sense data.=0D + //=0D + Packet->SenseDataLength =3D 0;=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 +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 +=0D + if (SIst0 & LSI_SIST0_PAR) {=0D + Packet->HostAdapterStatus =3D EFI_EXT_SCSI_STATUS_HOST_ADAPTER_PARITY_= ERROR;=0D + } else if (SIst0 & LSI_SIST0_RST) {=0D + Packet->HostAdapterStatus =3D EFI_EXT_SCSI_STATUS_HOST_ADAPTER_BUS_RES= ET;=0D + } else if (SIst0 & LSI_SIST0_UDC) {=0D + //=0D + // The target device is disconnected unexpectedly. According to UEFI s= pec,=0D + // this is TIMEOUT_COMMAND.=0D + //=0D + Packet->HostAdapterStatus =3D EFI_EXT_SCSI_STATUS_HOST_ADAPTER_TIMEOUT= _COMMAND;=0D + } else if (SIst0 & LSI_SIST0_SGE) {=0D + Packet->HostAdapterStatus =3D EFI_EXT_SCSI_STATUS_HOST_ADAPTER_DATA_OV= ERRUN_UNDERRUN;=0D + } else if (SIst1 & LSI_SIST1_HTH) {=0D + Packet->HostAdapterStatus =3D EFI_EXT_SCSI_STATUS_HOST_ADAPTER_TIMEOUT= ;=0D + } else if (SIst1 & LSI_SIST1_GEN) {=0D + Packet->HostAdapterStatus =3D EFI_EXT_SCSI_STATUS_HOST_ADAPTER_TIMEOUT= ;=0D + } else if (SIst1 & LSI_SIST1_STO) {=0D + Packet->HostAdapterStatus =3D EFI_EXT_SCSI_STATUS_HOST_ADAPTER_SELECTI= ON_TIMEOUT;=0D + } else {=0D + Packet->HostAdapterStatus =3D EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OTHER;= =0D + }=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,7 +501,7 @@ LsiScsiPassThru ( return Status;=0D }=0D =0D - return EFI_UNSUPPORTED;=0D + return LsiScsiProcessRequest (Dev, *Target, Lun, Packet);=0D }=0D =0D EFI_STATUS=0D @@ -474,6 +807,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 05deeed379fe..6ecf523f5a9e 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 @@ -25,6 +30,18 @@ typedef struct { // Count (DBC), a 24-bit register, so the maximum is 0xFFFFFF (16M= B-1).=0D //=0D UINT8 Data[SIZE_64KB];=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 @@ -34,6 +51,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 @@ -46,6 +64,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(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 6111449577a8..4c7abcec618f 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 ca13a3cb11d3..f16c00ad5b99 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