From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.groups.io with SMTP id smtpd.web10.10861.1585067710552792018 for ; Tue, 24 Mar 2020 09:35:10 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IMDloJFp; spf=pass (domain: redhat.com, ip: 216.205.24.74, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585067709; 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=FVtwOj00UFW4P5n6D6Q+7wwwlcdTD1YSn8LeSkdYuhY=; b=IMDloJFpsqCdsoyaACQBIXMcDCun1jV7uqj0li4qpvVDuF1+YjWZoLz0CVdl7fDOn6l7DQ 3wa/iv2Xrf/17qQ9rv46WlySfA9sxsrmPz94nXx3EsovDWTj/RThfZWXsKsWUmS56OI05h s4fk6Nj+bKXkEeySOeuhGS4vK8FJk8s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-311-rqu5ponYMZG9pobEEPg8ZQ-1; Tue, 24 Mar 2020 12:35:02 -0400 X-MC-Unique: rqu5ponYMZG9pobEEPg8ZQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F2159A1361; Tue, 24 Mar 2020 16:35:00 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-115-139.ams2.redhat.com [10.36.115.139]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03EDE5C241; Tue, 24 Mar 2020 16:34:56 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH 11/17] OvmfPkg/PvScsiDxe: Define device interface structures and constants From: "Laszlo Ersek" To: devel@edk2.groups.io, liran.alon@oracle.com Cc: nikita.leshchenko@oracle.com, aaron.young@oracle.com, jordan.l.justen@intel.com, ard.biesheuvel@linaro.org References: <20200316150113.104630-1-liran.alon@oracle.com> <20200316150113.104630-12-liran.alon@oracle.com> Message-ID: <77912e34-770a-9545-86ee-f8a150b4a71d@redhat.com> Date: Tue, 24 Mar 2020 17:34:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 03/24/20 16:35, Laszlo Ersek wrote: > On 03/16/20 16:01, Liran Alon wrote: >> These definitions will be used by the following commits to complete the >> implementation of PVSCSI device driver. >> >> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2567 >> Reviewed-by: Nikita Leshenko >> Signed-off-by: Liran Alon >> --- >> OvmfPkg/Include/IndustryStandard/PvScsi.h | 162 ++++++++++++++++++++++ >> 1 file changed, 162 insertions(+) >> >> diff --git a/OvmfPkg/Include/IndustryStandard/PvScsi.h b/OvmfPkg/Include/IndustryStandard/PvScsi.h >> index 004c0af84989..7bb6e664dfcd 100644 >> --- a/OvmfPkg/Include/IndustryStandard/PvScsi.h >> +++ b/OvmfPkg/Include/IndustryStandard/PvScsi.h >> @@ -18,4 +18,166 @@ >> #define PCI_VENDOR_ID_VMWARE (0x15ad) >> #define PCI_DEVICE_ID_VMWARE_PVSCSI (0x07c0) >> >> +// >> +// CDB (Command Descriptor Block) with size above this constant >> +// should be considered out-of-band >> +// >> +#define PVSCSI_CDB_MAX_SIZE (16) >> + >> +enum PVSCSI_BAR0_OFFSETS { >> + PVSCSI_REG_OFFSET_COMMAND = 0x0, >> + PVSCSI_REG_OFFSET_COMMAND_DATA = 0x4, >> + PVSCSI_REG_OFFSET_COMMAND_STATUS = 0x8, >> + PVSCSI_REG_OFFSET_LAST_STS_0 = 0x100, >> + PVSCSI_REG_OFFSET_LAST_STS_1 = 0x104, >> + PVSCSI_REG_OFFSET_LAST_STS_2 = 0x108, >> + PVSCSI_REG_OFFSET_LAST_STS_3 = 0x10c, >> + PVSCSI_REG_OFFSET_INTR_STATUS = 0x100c, >> + PVSCSI_REG_OFFSET_INTR_MASK = 0x2010, >> + PVSCSI_REG_OFFSET_KICK_NON_RW_IO = 0x3014, >> + PVSCSI_REG_OFFSET_DEBUG = 0x3018, >> + PVSCSI_REG_OFFSET_KICK_RW_IO = 0x4018, >> +}; > > (1) In the edk2 coding style, we introduce typedefs (too). So that, in > case we need a variable of this type, we don't have to write > > enum PVSCSI_BAR0_OFFSETS MyVar; > > just > > PVSCSI_BAR0_OFFSETS MyVar; > > For example: > > typedef enum { > Blah > } PVSCSI_BAR0_OFFSETS; > > > (2) Enumeration constants are spelled in CamelCase. > > Example: EfiPciIoAttributeOperationGet. (See the > EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION typedef in > "MdePkg/Include/Protocol/PciIo.h".) > >> + >> +// >> +// Define Interrupt-Status register flags >> +// >> +#define PVSCSI_INTR_CMPL_0 (1 << 0) >> +#define PVSCSI_INTR_CMPL_1 (1 << 1) > > (3) I suggest using the BIT0 and BIT1 macros, rather than open-coding > the shifts. > >> +#define PVSCSI_INTR_CMPL_MASK (PVSCSI_INTR_CMPL_0 | PVSCSI_INTR_CMPL_1) >> + >> +enum PVSCSI_COMMANDS { >> + PVSCSI_CMD_FIRST = 0, >> + PVSCSI_CMD_ADAPTER_RESET = 1, >> + PVSCSI_CMD_ISSUE_SCSI = 2, >> + PVSCSI_CMD_SETUP_RINGS = 3, >> + PVSCSI_CMD_RESET_BUS = 4, >> + PVSCSI_CMD_RESET_DEVICE = 5, >> + PVSCSI_CMD_ABORT_CMD = 6, >> + PVSCSI_CMD_CONFIG = 7, >> + PVSCSI_CMD_SETUP_MSG_RING = 8, >> + PVSCSI_CMD_DEVICE_UNPLUG = 9, >> + PVSCSI_CMD_LAST = 10 >> +}; > > (4) Same as (1) and (2). > >> + >> +#define PVSCSI_SETUP_RINGS_MAX_NUM_PAGES (32) >> + >> +#pragma pack (1) >> +typedef struct { >> + UINT32 ReqRingNumPages; >> + UINT32 CmpRingNumPages; >> + UINT64 RingsStatePPN; >> + UINT64 ReqRingPPNs[PVSCSI_SETUP_RINGS_MAX_NUM_PAGES]; >> + UINT64 CmpRingPPNs[PVSCSI_SETUP_RINGS_MAX_NUM_PAGES]; >> +} PVSCSI_CMD_DESC_SETUP_RINGS; >> +#pragma pack () >> + >> +#define PVSCSI_MAX_CMD_DATA_WORDS \ >> + (sizeof (PVSCSI_CMD_DESC_SETUP_RINGS) / sizeof (UINT32)) >> + >> +#pragma pack (1) >> +typedef struct { >> + UINT32 ReqProdIdx; >> + UINT32 ReqConsIdx; >> + UINT32 ReqNumEntriesLog2; >> + >> + UINT32 CmpProdIdx; >> + UINT32 CmpConsIdx; >> + UINT32 CmpNumEntriesLog2; >> + >> + UINT8 Pad[104]; >> + >> + UINT32 MsgProdIdx; >> + UINT32 MsgConsIdx; >> + UINT32 MsgNumEntriesLog2; >> +} PVSCSI_RINGS_STATE; >> +#pragma pack () >> + >> +// >> +// Define PVSCSI request descriptor tags >> +// >> +#define PVSCSI_SIMPLE_QUEUE_TAG (0x20) >> + >> +// >> +// Define PVSCSI request descriptor flags >> +// >> +#define PVSCSI_FLAG_CMD_WITH_SG_LIST (1 << 0) >> +#define PVSCSI_FLAG_CMD_OUT_OF_BAND_CDB (1 << 1) >> +#define PVSCSI_FLAG_CMD_DIR_NONE (1 << 2) >> +#define PVSCSI_FLAG_CMD_DIR_TOHOST (1 << 3) >> +#define PVSCSI_FLAG_CMD_DIR_TODEVICE (1 << 4) > > (5) Same as (3). > >> + >> +#pragma pack (1) >> +typedef struct { >> + UINT64 Context; >> + UINT64 DataAddr; >> + UINT64 DataLen; >> + UINT64 SenseAddr; >> + UINT32 SenseLen; >> + UINT32 Flags; >> + UINT8 Cdb[16]; >> + UINT8 CdbLen; >> + UINT8 Lun[8]; >> + UINT8 Tag; >> + UINT8 Bus; >> + UINT8 Target; >> + UINT8 vCPUHint; (8) This should be spelled "VcpuHint", because: - CamelCase - the 2nd and further letters in sub-acronyms are lowercased in edk2. Thanks Laszlo >> + UINT8 Unused[59]; >> +} PVSCSI_RING_REQ_DESC; >> +#pragma pack () >> + >> +// >> +// Host adapter status/error codes >> +// >> +enum PVSCSI_HOST_BUS_ADAPTER_STATUS { >> + BTSTAT_SUCCESS = 0x00, // CCB complete normally with no errors >> + BTSTAT_LINKED_COMMAND_COMPLETED = 0x0a, >> + BTSTAT_LINKED_COMMAND_COMPLETED_WITH_FLAG = 0x0b, >> + BTSTAT_DATA_UNDERRUN = 0x0c, >> + BTSTAT_SELTIMEO = 0x11, // SCSI selection timeout >> + BTSTAT_DATARUN = 0x12, // Data overrun/underrun >> + BTSTAT_BUSFREE = 0x13, // Unexpected bus free >> + BTSTAT_INVPHASE = 0x14, // >> + // Invalid bus phase or sequence requested by >> + // target >> + // >> + BTSTAT_LUNMISMATCH = 0x17, // Linked CCB has different LUN from first CCB >> + BTSTAT_SENSFAILED = 0x1b, // Auto request sense failed >> + BTSTAT_TAGREJECT = 0x1c, // >> + // SCSI II tagged queueing message rejected by >> + // target >> + // >> + BTSTAT_BADMSG = 0x1d, // >> + // Unsupported message received by the host >> + // adapter >> + // >> + BTSTAT_HAHARDWARE = 0x20, // Host adapter hardware failed >> + BTSTAT_NORESPONSE = 0x21, // >> + // Target did not respond to SCSI ATN sent a >> + // SCSI RST >> + // >> + BTSTAT_SENTRST = 0x22, // Host adapter asserted a SCSI RST >> + BTSTAT_RECVRST = 0x23, // Other SCSI devices asserted a SCSI RST >> + BTSTAT_DISCONNECT = 0x24, // >> + // Target device reconnected improperly >> + // (w/o tag) >> + // >> + BTSTAT_BUSRESET = 0x25, // Host adapter issued BUS device reset >> + BTSTAT_ABORTQUEUE = 0x26, // Abort queue generated >> + BTSTAT_HASOFTWARE = 0x27, // Host adapter software error >> + BTSTAT_HATIMEOUT = 0x30, // Host adapter hardware timeout error >> + BTSTAT_SCSIPARITY = 0x34, // SCSI parity error detected >> +}; > > (6) Same as (1) and (2). > > (7) Please use a PvScsi prefix in these enum constants too. > >> + >> +#pragma pack (1) >> +typedef struct { >> + UINT64 Context; >> + UINT64 DataLen; >> + UINT32 SenseLen; >> + UINT16 HostStatus; >> + UINT16 ScsiStatus; >> + UINT32 Pad[2]; >> +} PVSCSI_RING_CMP_DESC; >> +#pragma pack () >> + >> #endif // __PVSCSI_H_ >> > > Thanks! > Laszlo >