Skip to content

Commit

Permalink
Merged current inbox code except for DDKSPLIT (#474)
Browse files Browse the repository at this point in the history
* Merged current inbox code except for DDKSPLIT
* 19H1 inbox code except for DDKSPLIT and storport_p.h
* Removed internal code
  • Loading branch information
aktsuda authored Jun 24, 2020
1 parent 9afd930 commit dbadff8
Show file tree
Hide file tree
Showing 16 changed files with 4,549 additions and 1,223 deletions.
107 changes: 53 additions & 54 deletions storage/miniports/storahci/src/ahci.h

Large diffs are not rendered by default.

1,633 changes: 1,404 additions & 229 deletions storage/miniports/storahci/src/common.c

Large diffs are not rendered by default.

137 changes: 119 additions & 18 deletions storage/miniports/storahci/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Revision History:

#define IDE_FEATURE_INVALID 0xFF

#define SCSI_VENDOR_ID_LENGTH (8)

//
// ATA function code
Expand Down Expand Up @@ -84,7 +85,6 @@ Revision History:
#define ATA_FLAGS_ACTIVE_REFERENCE (1 << 10) // indicates Active Reference needs to be acquired before processing the Srb and released after processing the Srb
#define ATA_FLAGS_SENSEDATA_SET (1 << 11) // indicates sense data has been set to the Srb


//
// helper macros
//
Expand Down Expand Up @@ -114,9 +114,23 @@ typedef enum _AHCI_ETW_EVENT_IDS {
AhciEtwEventUnitHybridEvict = 11,
AhciEtwEventUnitHybridSetDirtyThreshold = 12,
AhciEtwEventUnitHybridWriteThrough = 13,
AhciEtwEventUnitFirmwareIoctl = 14,
AhciEtwEventUnitFirmwareInfo = 15,
AhciEtwEventUnitFirmwareDownload = 16,
AhciEtwEventUnitFirmwareDownloadComplete = 17,
AhciEtwEventUnitFirmwareActivate = 18,
AhciEtwEventUnitFirmwareActivateComplete = 19,
AhciEtwEventUnitGetPhysicalElementStatusComplete = 20,
AhciEtwEventUnitRemoveElementAndTruncateComplete = 21,
AhciEtwEventUnitGetInternalStatusDataHeaderComplete = 22,
AhciEtwEventUnitGetInternalStatusDataComplete = 23,
AhciEtwEventBuildIO = 24,
AhciEtwEventStartIO = 25,
AhciEtwEventHandleInterrupt = 26,
AhciEtwEventPortReset = 27,
AhciEtwEventIOCompletion = 28
} AHCI_ETW_EVENT_IDS, *PAHCI_ETW_EVENT_IDS;


//
// task file register contents
//
Expand Down Expand Up @@ -312,6 +326,14 @@ typedef struct _HYBRID_EVICT_CONTEXT {

} HYBRID_EVICT_CONTEXT, *PHYBRID_EVICT_CONTEXT;

__inline
BOOLEAN
IsUnknownDevice(
_In_ PATA_DEVICE_PARAMETERS DeviceParameters
)
{
return (DeviceParameters->AtaDeviceType == DeviceUnknown);
}

__inline
BOOLEAN
Expand Down Expand Up @@ -601,7 +623,8 @@ __inline
AhciAllocateDmaBuffer (
_In_ PVOID AdapterExtension,
_In_ ULONG BufferLength,
_Post_writable_byte_size_(BufferLength) PVOID* Buffer
_Post_writable_byte_size_(BufferLength) PVOID* Buffer,
_Out_ PSTOR_PHYSICAL_ADDRESS PhysicalAddress
)
{
ULONG status;
Expand All @@ -613,15 +636,16 @@ AhciAllocateDmaBuffer (
maxPhysicalAddress.QuadPart = 0x7FFFFFFF; // (2GB - 1)
boundaryPhysicalAddress.QuadPart = 0;

status = StorPortAllocateDmaMemory(AdapterExtension,
BufferLength,
minPhysicalAddress,
maxPhysicalAddress,
boundaryPhysicalAddress,
MmCached,
MM_ANY_NODE_OK,
Buffer,
PhysicalAddress);

status = StorPortAllocateContiguousMemorySpecifyCacheNode(AdapterExtension,
BufferLength,
minPhysicalAddress,
maxPhysicalAddress,
boundaryPhysicalAddress,
MmCached,
MM_ANY_NODE_OK,
Buffer);
return status;
}

Expand All @@ -631,14 +655,18 @@ __inline
AhciFreeDmaBuffer (
_In_ PVOID AdapterExtension,
_In_ ULONG_PTR BufferLength,
_In_reads_bytes_(BufferLength) _Post_invalid_ PVOID Buffer
_In_reads_bytes_(BufferLength) _Post_invalid_ PVOID Buffer,
_In_opt_ STOR_PHYSICAL_ADDRESS PhysicalAddress
)
{
ULONG status;
status = StorPortFreeContiguousMemorySpecifyCache(AdapterExtension,
Buffer,
BufferLength,
MmCached);
ULONG status;

status = StorPortFreeDmaMemory(AdapterExtension,
Buffer,
BufferLength,
MmCached,
PhysicalAddress);

return status;
}

Expand Down Expand Up @@ -862,6 +890,33 @@ AtaReportLunsCommand(
_In_ PVOID Context
);

ULONG
AtaGetPhysicalElementStatusRequest (
_In_ PAHCI_CHANNEL_EXTENSION ChannelExtension,
_In_ PSTORAGE_REQUEST_BLOCK Srb,
_In_ PCDB Cdb
);

ULONG
AtaRemoveElementAndTruncateRequest (
_In_ PAHCI_CHANNEL_EXTENSION ChannelExtension,
_In_ PSTORAGE_REQUEST_BLOCK Srb,
_In_ PCDB Cdb
);

ULONG
AtaGetDeviceCurrentInternalStatusData(
_In_ PAHCI_CHANNEL_EXTENSION ChannelExtension,
_In_ PSTORAGE_REQUEST_BLOCK Srb,
_In_ PCDB Cdb
);

ULONG
AtaGetDeviceCurrentInternalStatusDataHeader(
_In_ PAHCI_CHANNEL_EXTENSION ChannelExtension,
_In_ PSTORAGE_REQUEST_BLOCK Srb,
_In_ PCDB Cdb
);

UCHAR
AtaMapError(
Expand Down Expand Up @@ -965,11 +1020,57 @@ FirmwareIoctlProcess(
);


//
// AHCI Telemetry event related.
//
#define AHCI_TELEMETRY_EVENT_VERSION 0x1
#define AHCI_TELEMETRY_DRIVER_VERSION 0x1

#define AHCI_TELEMETRY_FLAG_NOT_SUPPRESS_LOGGING 0x1

typedef enum _AHCI_TELEMETRY_EVENT_ID {
AhciTelemetryEventIdGeneral = 0,
AhciTelemetryEventIdPortReset = 1,
AhciTelemetryEventIdPortRunningStartFail = 2,
AhciTelemetryEventIdPortErrorRecovery = 3,
AhciTelemetryEventIdNonqueuedErrorRecovery = 4,
AhciTelemetryEventIdNCQErrorRecovery = 5,
AhciTelemetryEventIdNCQErrorRecoveryComplete = 6,
AhciTelemetryEventIdResetBus = 7,
AhciTelemetryEventIdResetDeviceRequest = 8,
AhciTelemetryEventIdSurpriseRemove = 9,
AhciTelemetryEventIdLpmAdaptiveSetting = 10,
AhciTelemetryEventIdLpmSettingsModes = 11,
AhciTelemetryEventIdPortStartSuccess = 12,
AhciTelemetryEventIdReservedSlotStuck = 13,
AhciTelemetryEventIdMax = 256
} AHCI_TELEMETRY_EVENT_ID, *PAHCI_TELEMETRY_EVENT_ID;

//
// AHCI mark device failure related.
//
#define AHCI_BUS_CHANGE_WARNING_THROTTLE_MASK (0x1 << 0)
#define AHCI_BUS_CHANGE_COUNT_WARNING_THRESHOLD (20)

#define AHCI_NCQ_ERROR_WARNING_THROTTLE_MASK (0x1 << 1)
#define AHCI_NCQ_ERROR_COUNT_WARNING_THRESHOLD (100)

#define AHCI_NON_QUEUED_ERROR_WARNING_THROTTLE_MASK (0x1 << 2)
#define AHCI_NON_QUEUED_ERROR_COUNT_WARNING_THRESHOLD (100)

#define AHCI_DEVICE_STUCK_WARNING_THROTTLE_MASK (0x1 << 3)

typedef enum _AHCI_DEVICE_FAILURE_REASON {
AhciDeviceFailureUnspecific = 0,
AhciDeviceFailureTooManyBusChange = 1,
AhciDeviceFailureTooManyNCQError = 2,
AhciDeviceFailureTooManyNonQueuedError = 3,
AhciDeviceFailureDeviceStuck = 4
} AHCI_DEVICE_FAILURE_REASON, *PAHCI_DEVICE_FAILURE_REASON;

#if _MSC_VER >= 1200
#pragma warning(pop)
#else
#pragma warning(default:4214)
#pragma warning(default:4201)
#endif

96 changes: 96 additions & 0 deletions storage/miniports/storahci/src/data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*++
Copyright (c) 2017 Microsoft Corporation
Module Name:
data.h
Abstract:
Definitions needed by storahci log/diagnostic function.
Author:
--*/

#pragma once

//
// Diagnostic data definitions for STORAHCI
//

#define MAX_EXECUTION_HISTORY_ENTRY_COUNT 200 // 200 entries take up 20KB

typedef struct _SLOT_MANAGER {

ULONG HighPriorityAttribute;

ULONG NCQueueSlice;
ULONG NormalQueueSlice;
ULONG SingleIoSlice;

ULONG CommandsIssued;
ULONG CommandsToComplete;

//
// These issued slices are used to determine the type of command
// being programmed to adapter.
// They are used instead of reading PxCI and PxSACT.
//
ULONG NCQueueSliceIssued;
ULONG NormalQueueSliceIssued;
ULONG SingleIoSliceIssued;

ULONG Reserved;

} SLOT_MANAGER, *PSLOT_MANAGER;

typedef struct _EXECUTION_HISTORY {

ULONG Function;
ULONG IS;
SLOT_MANAGER SlotManager; //SLOT_MANAGER from _AHCI_CHANNEL_EXTENSION
ULONG Px[0x10]; //Px registers value, end to AHCI_SNOTIFICATION -- SNTF
LARGE_INTEGER TimeStamp;

} EXECUTION_HISTORY, *PEXECUTION_HISTORY;

typedef struct _ATA_IO_RECORD {

ULONG SuccessCount;

ULONG CrcErrorCount;
ULONG MediaErrorCount;
ULONG EndofMediaCount;
ULONG IllegalCommandCount;
ULONG AbortedCommandCount;
ULONG DeviceFaultCount;

ULONG OtherErrorCount;

ULONG NcqReadLogErrorCount; // used to record the READ LOG EXT command error count when used for NCQ Error Recovery.

ULONG PortDriverResetCount;
ULONG TotalResetCount;

} ATA_IO_RECORD, *PATA_IO_RECORD;

typedef struct _STORAGE_DIAGNOSTIC_AHCI_EXECUTION_HISTORY {

ULONG ExecutionHistoryCount;
ULONG ExecutionHistoryIndex;
EXECUTION_HISTORY History[MAX_EXECUTION_HISTORY_ENTRY_COUNT];

} STORAGE_DIAGNOSTIC_AHCI_EXECUTION_HISTORY, *PSTORAGE_DIAGNOSTIC_AHCI_EXECUTION_HISTORY;

typedef struct _STORAGE_DIAGNOSTIC_AHCI_DATA {

ULONG Version;
ULONG Count;
STORAGE_DIAGNOSTIC_AHCI_EXECUTION_HISTORY ExecutionHistory;
AHCI_PORT Registers;
ATA_IO_RECORD IoRecord;

} STORAGE_DIAGNOSTIC_AHCI_DATA, *PSTORAGE_DIAGNOSTIC_AHCI_DATA;

Loading

0 comments on commit dbadff8

Please sign in to comment.