2016-06-02 14:43:56 +00:00
|
|
|
|
/*
|
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
|
* LICENSE: GNU GPLv2 only as published by the Free Software Foundation
|
|
|
|
|
* PURPOSE: To Implement AHCI Miniport driver targeting storport NT 5.2
|
|
|
|
|
* PROGRAMMERS: Aman Priyadarshi (aman.eureka@gmail.com)
|
|
|
|
|
*/
|
|
|
|
|
|
2016-06-02 14:13:06 +00:00
|
|
|
|
#include "storahci.h"
|
|
|
|
|
|
2016-06-03 15:54:21 +00:00
|
|
|
|
/**
|
|
|
|
|
* @name AhciPortInitialize
|
|
|
|
|
* @implemented
|
|
|
|
|
*
|
|
|
|
|
* Initialize port by setting up PxCLB & PxFB Registers
|
|
|
|
|
*
|
2016-06-10 08:27:20 +00:00
|
|
|
|
* @param PortExtension
|
2016-06-03 15:54:21 +00:00
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
* Return true if intialization was successful
|
|
|
|
|
*/
|
2016-06-09 23:47:19 +00:00
|
|
|
|
BOOLEAN
|
|
|
|
|
AhciPortInitialize (
|
2016-06-10 08:27:20 +00:00
|
|
|
|
__in PAHCI_PORT_EXTENSION PortExtension
|
2016-06-09 23:47:19 +00:00
|
|
|
|
)
|
2016-06-03 15:54:21 +00:00
|
|
|
|
{
|
2016-07-04 19:01:07 +00:00
|
|
|
|
AHCI_PORT_CMD cmd;
|
2016-06-10 08:27:20 +00:00
|
|
|
|
ULONG mappedLength, portNumber;
|
2016-06-03 15:54:21 +00:00
|
|
|
|
PAHCI_MEMORY_REGISTERS abar;
|
|
|
|
|
PAHCI_ADAPTER_EXTENSION adapterExtension;
|
|
|
|
|
STOR_PHYSICAL_ADDRESS commandListPhysical, receivedFISPhysical;
|
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
DebugPrint("AhciPortInitialize()\n");
|
|
|
|
|
|
2016-06-10 08:27:20 +00:00
|
|
|
|
adapterExtension = PortExtension->AdapterExtension;
|
2016-06-03 15:54:21 +00:00
|
|
|
|
abar = adapterExtension->ABAR_Address;
|
2016-06-10 08:27:20 +00:00
|
|
|
|
portNumber = PortExtension->PortNumber;
|
2016-06-07 11:05:32 +00:00
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
NT_ASSERT(abar != NULL);
|
2016-06-16 21:14:03 +00:00
|
|
|
|
NT_ASSERT(portNumber < adapterExtension->PortCount);
|
2016-06-09 23:47:19 +00:00
|
|
|
|
|
2016-06-10 08:27:20 +00:00
|
|
|
|
PortExtension->Port = &abar->PortList[portNumber];
|
2016-06-03 15:54:21 +00:00
|
|
|
|
|
2016-06-10 08:27:20 +00:00
|
|
|
|
commandListPhysical = StorPortGetPhysicalAddress(adapterExtension,
|
|
|
|
|
NULL,
|
|
|
|
|
PortExtension->CommandList,
|
|
|
|
|
&mappedLength);
|
2016-06-09 23:47:19 +00:00
|
|
|
|
|
2016-06-10 08:27:20 +00:00
|
|
|
|
if ((mappedLength == 0) || ((commandListPhysical.LowPart % 1024) != 0))
|
2016-06-09 23:47:19 +00:00
|
|
|
|
{
|
|
|
|
|
DebugPrint("\tcommandListPhysical mappedLength:%d\n", mappedLength);
|
2016-06-03 15:54:21 +00:00
|
|
|
|
return FALSE;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
}
|
2016-06-03 15:54:21 +00:00
|
|
|
|
|
2016-06-10 08:27:20 +00:00
|
|
|
|
receivedFISPhysical = StorPortGetPhysicalAddress(adapterExtension,
|
|
|
|
|
NULL,
|
|
|
|
|
PortExtension->ReceivedFIS,
|
|
|
|
|
&mappedLength);
|
2016-06-09 23:47:19 +00:00
|
|
|
|
|
2016-06-10 08:27:20 +00:00
|
|
|
|
if ((mappedLength == 0) || ((receivedFISPhysical.LowPart % 256) != 0))
|
2016-06-09 23:47:19 +00:00
|
|
|
|
{
|
|
|
|
|
DebugPrint("\treceivedFISPhysical mappedLength:%d\n", mappedLength);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-04 19:01:07 +00:00
|
|
|
|
// Ensure that the controller is not in the running state by reading and examining each
|
|
|
|
|
// implemented port’s PxCMD register. If PxCMD.ST, PxCMD.CR, PxCMD.FRE and
|
|
|
|
|
// PxCMD.FR are all cleared, the port is in an idle state. Otherwise, the port is not idle and
|
|
|
|
|
// should be placed in the idle state prior to manipulating HBA and port specific registers.
|
|
|
|
|
// System software places a port into the idle state by clearing PxCMD.ST and waiting for
|
|
|
|
|
// PxCMD.CR to return ‘0’ when read. Software should wait at least 500 milliseconds for
|
|
|
|
|
// this to occur. If PxCMD.FRE is set to ‘1’, software should clear it to ‘0’ and wait at least
|
|
|
|
|
// 500 milliseconds for PxCMD.FR to return ‘0’ when read. If PxCMD.CR or PxCMD.FR do
|
|
|
|
|
// not clear to ‘0’ correctly, then software may attempt a port reset or a full HBA reset to recove
|
|
|
|
|
|
|
|
|
|
// TODO: Check if port is in idle state or not, if not then restart port
|
|
|
|
|
cmd.Status = StorPortReadRegisterUlong(adapterExtension, &PortExtension->Port->CMD);
|
|
|
|
|
if ((cmd.FR != 0) || (cmd.CR != 0) || (cmd.FRE != 0) || (cmd.ST != 0))
|
|
|
|
|
{
|
|
|
|
|
DebugPrint("\tPort is not idle: %x\n", cmd);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-03 15:54:21 +00:00
|
|
|
|
// 10.1.2 For each implemented port, system software shall allocate memory for and program:
|
|
|
|
|
// PxCLB and PxCLBU (if CAP.S64A is set to ‘1’)
|
|
|
|
|
// PxFB and PxFBU (if CAP.S64A is set to ‘1’)
|
2016-06-09 23:47:19 +00:00
|
|
|
|
// Note: Assuming 32bit support only
|
2016-06-10 08:27:20 +00:00
|
|
|
|
StorPortWriteRegisterUlong(adapterExtension, &PortExtension->Port->CLB, commandListPhysical.LowPart);
|
2016-06-20 11:49:22 +00:00
|
|
|
|
if (IsAdapterCAPS64(adapterExtension->CAP))
|
2016-06-15 17:07:26 +00:00
|
|
|
|
{
|
|
|
|
|
StorPortWriteRegisterUlong(adapterExtension, &PortExtension->Port->CLBU, commandListPhysical.HighPart);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-10 08:27:20 +00:00
|
|
|
|
StorPortWriteRegisterUlong(adapterExtension, &PortExtension->Port->FB, receivedFISPhysical.LowPart);
|
2016-06-20 11:49:22 +00:00
|
|
|
|
if (IsAdapterCAPS64(adapterExtension->CAP))
|
2016-06-15 17:07:26 +00:00
|
|
|
|
{
|
|
|
|
|
StorPortWriteRegisterUlong(adapterExtension, &PortExtension->Port->FBU, receivedFISPhysical.HighPart);
|
|
|
|
|
}
|
2016-06-03 15:54:21 +00:00
|
|
|
|
|
2016-06-27 12:58:04 +00:00
|
|
|
|
PortExtension->IdentifyDeviceDataPhysicalAddress = StorPortGetPhysicalAddress(adapterExtension,
|
|
|
|
|
NULL,
|
|
|
|
|
PortExtension->IdentifyDeviceData,
|
|
|
|
|
&mappedLength);
|
|
|
|
|
|
2016-06-07 11:05:32 +00:00
|
|
|
|
// set device power state flag to D0
|
2016-06-10 08:27:20 +00:00
|
|
|
|
PortExtension->DevicePowerState = StorPowerDeviceD0;
|
2016-06-07 11:05:32 +00:00
|
|
|
|
|
|
|
|
|
// clear pending interrupts
|
2016-07-04 19:01:07 +00:00
|
|
|
|
StorPortWriteRegisterUlong(adapterExtension, &PortExtension->Port->SERR, (ULONG)~0);
|
|
|
|
|
StorPortWriteRegisterUlong(adapterExtension, &PortExtension->Port->IS, (ULONG)~0);
|
|
|
|
|
StorPortWriteRegisterUlong(adapterExtension, adapterExtension->IS, (1 << PortExtension->PortNumber));
|
2016-06-07 11:05:32 +00:00
|
|
|
|
|
2016-06-03 15:54:21 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}// -- AhciPortInitialize();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @name AhciAllocateResourceForAdapter
|
|
|
|
|
* @implemented
|
|
|
|
|
*
|
|
|
|
|
* Allocate memory from poll for required pointers
|
|
|
|
|
*
|
2016-06-10 08:27:20 +00:00
|
|
|
|
* @param AdapterExtension
|
2016-06-03 15:54:21 +00:00
|
|
|
|
* @param ConfigInfo
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
* return TRUE if allocation was successful
|
|
|
|
|
*/
|
2016-06-09 23:47:19 +00:00
|
|
|
|
BOOLEAN
|
|
|
|
|
AhciAllocateResourceForAdapter (
|
2016-06-10 08:27:20 +00:00
|
|
|
|
__in PAHCI_ADAPTER_EXTENSION AdapterExtension,
|
|
|
|
|
__in PPORT_CONFIGURATION_INFORMATION ConfigInfo
|
2016-06-09 23:47:19 +00:00
|
|
|
|
)
|
2016-06-03 15:54:21 +00:00
|
|
|
|
{
|
2016-06-27 12:58:04 +00:00
|
|
|
|
PCHAR nonCachedExtension, tmp;
|
2016-06-09 23:47:19 +00:00
|
|
|
|
ULONG status, index, NCS, AlignedNCS;
|
|
|
|
|
ULONG portCount, portImplemented, nonCachedExtensionSize;
|
2016-06-03 15:54:21 +00:00
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
DebugPrint("AhciAllocateResourceForAdapter()\n");
|
2016-06-04 12:52:38 +00:00
|
|
|
|
|
2016-06-10 08:27:20 +00:00
|
|
|
|
NCS = AHCI_Global_Port_CAP_NCS(AdapterExtension->CAP);
|
2016-06-09 23:47:19 +00:00
|
|
|
|
AlignedNCS = ROUND_UP(NCS, 8);
|
2016-06-03 15:54:21 +00:00
|
|
|
|
|
2016-06-10 08:27:20 +00:00
|
|
|
|
// get port count -- Number of set bits in `AdapterExtension->PortImplemented`
|
2016-06-03 15:54:21 +00:00
|
|
|
|
portCount = 0;
|
2016-06-10 08:27:20 +00:00
|
|
|
|
portImplemented = AdapterExtension->PortImplemented;
|
|
|
|
|
|
2016-06-16 21:14:03 +00:00
|
|
|
|
NT_ASSERT(portImplemented != 0);
|
|
|
|
|
for (index = MAXIMUM_AHCI_PORT_COUNT - 1; index > 0; index--)
|
|
|
|
|
if ((portImplemented & (1 << index)) != 0)
|
|
|
|
|
break;
|
2016-06-09 23:47:19 +00:00
|
|
|
|
|
2016-06-16 21:14:03 +00:00
|
|
|
|
portCount = index + 1;
|
2016-06-09 23:47:19 +00:00
|
|
|
|
DebugPrint("\tPort Count: %d\n", portCount);
|
2016-06-03 15:54:21 +00:00
|
|
|
|
|
2016-06-16 21:14:03 +00:00
|
|
|
|
AdapterExtension->PortCount = portCount;
|
2016-06-03 15:54:21 +00:00
|
|
|
|
nonCachedExtensionSize = sizeof(AHCI_COMMAND_HEADER) * AlignedNCS + //should be 1K aligned
|
2016-06-27 12:58:04 +00:00
|
|
|
|
sizeof(AHCI_RECEIVED_FIS) +
|
|
|
|
|
sizeof(IDENTIFY_DEVICE_DATA);
|
2016-06-03 15:54:21 +00:00
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
// align nonCachedExtensionSize to 1024
|
|
|
|
|
nonCachedExtensionSize = ROUND_UP(nonCachedExtensionSize, 1024);
|
|
|
|
|
|
2016-06-10 08:27:20 +00:00
|
|
|
|
AdapterExtension->NonCachedExtension = StorPortGetUncachedExtension(AdapterExtension,
|
|
|
|
|
ConfigInfo,
|
|
|
|
|
nonCachedExtensionSize * portCount);
|
2016-06-09 23:47:19 +00:00
|
|
|
|
|
2016-06-10 08:27:20 +00:00
|
|
|
|
if (AdapterExtension->NonCachedExtension == NULL)
|
2016-06-09 23:47:19 +00:00
|
|
|
|
{
|
|
|
|
|
DebugPrint("\tadapterExtension->NonCachedExtension == NULL\n");
|
2016-06-03 15:54:21 +00:00
|
|
|
|
return FALSE;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
}
|
2016-06-03 15:54:21 +00:00
|
|
|
|
|
2016-06-10 08:27:20 +00:00
|
|
|
|
nonCachedExtension = AdapterExtension->NonCachedExtension;
|
2016-06-09 23:47:19 +00:00
|
|
|
|
AhciZeroMemory(nonCachedExtension, nonCachedExtensionSize * portCount);
|
2016-06-03 15:54:21 +00:00
|
|
|
|
|
2016-06-16 21:14:03 +00:00
|
|
|
|
for (index = 0; index < portCount; index++)
|
2016-06-03 15:54:21 +00:00
|
|
|
|
{
|
2016-06-10 08:27:20 +00:00
|
|
|
|
AdapterExtension->PortExtension[index].IsActive = FALSE;
|
|
|
|
|
if ((AdapterExtension->PortImplemented & (1 << index)) != 0)
|
2016-06-03 15:54:21 +00:00
|
|
|
|
{
|
2016-06-10 08:27:20 +00:00
|
|
|
|
AdapterExtension->PortExtension[index].PortNumber = index;
|
|
|
|
|
AdapterExtension->PortExtension[index].IsActive = TRUE;
|
|
|
|
|
AdapterExtension->PortExtension[index].AdapterExtension = AdapterExtension;
|
|
|
|
|
AdapterExtension->PortExtension[index].CommandList = nonCachedExtension;
|
2016-06-27 12:58:04 +00:00
|
|
|
|
|
|
|
|
|
tmp = (PCHAR)(nonCachedExtension + sizeof(AHCI_COMMAND_HEADER) * AlignedNCS);
|
|
|
|
|
|
|
|
|
|
AdapterExtension->PortExtension[index].ReceivedFIS = (PAHCI_RECEIVED_FIS)tmp;
|
|
|
|
|
AdapterExtension->PortExtension[index].IdentifyDeviceData = (PIDENTIFY_DEVICE_DATA)(tmp + sizeof(AHCI_RECEIVED_FIS));
|
2016-06-09 23:47:19 +00:00
|
|
|
|
nonCachedExtension += nonCachedExtensionSize;
|
2016-06-03 15:54:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}// -- AhciAllocateResourceForAdapter();
|
|
|
|
|
|
2016-07-04 19:01:07 +00:00
|
|
|
|
/**
|
|
|
|
|
* @name AhciStartPort
|
|
|
|
|
* @implemented
|
|
|
|
|
*
|
|
|
|
|
* Try to start the port device
|
|
|
|
|
*
|
|
|
|
|
* @param AdapterExtension
|
|
|
|
|
* @param PortExtension
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
BOOLEAN
|
|
|
|
|
AhciStartPort (
|
|
|
|
|
__in PAHCI_PORT_EXTENSION PortExtension
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
ULONG index;
|
|
|
|
|
AHCI_PORT_CMD cmd;
|
|
|
|
|
AHCI_SERIAL_ATA_STATUS ssts;
|
|
|
|
|
AHCI_SERIAL_ATA_CONTROL sctl;
|
|
|
|
|
PAHCI_ADAPTER_EXTENSION AdapterExtension;
|
|
|
|
|
|
|
|
|
|
DebugPrint("AhciStartPort()\n");
|
|
|
|
|
|
|
|
|
|
AdapterExtension = PortExtension->AdapterExtension;
|
|
|
|
|
cmd.Status = StorPortReadRegisterUlong(AdapterExtension, &PortExtension->Port->CMD);
|
|
|
|
|
|
|
|
|
|
if ((cmd.FR == 1) && (cmd.CR == 1) && (cmd.FRE == 1) && (cmd.ST == 1))
|
|
|
|
|
{
|
|
|
|
|
// Already Running
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd.SUD = 1;
|
|
|
|
|
StorPortWriteRegisterUlong(AdapterExtension, &PortExtension->Port->CMD, cmd.Status);
|
|
|
|
|
|
|
|
|
|
if (((cmd.FR == 1) && (cmd.FRE == 0)) ||
|
|
|
|
|
((cmd.CR == 1) && (cmd.ST == 0)))
|
|
|
|
|
{
|
|
|
|
|
DebugPrint("\tCOMRESET\n");
|
|
|
|
|
// perform COMRESET
|
|
|
|
|
// section 10.4.2
|
|
|
|
|
|
|
|
|
|
// Software causes a port reset (COMRESET) by writing 1h to the PxSCTL.DET field to invoke a
|
|
|
|
|
// COMRESET on the interface and start a re-establishment of Phy layer communications. Software shall
|
|
|
|
|
// wait at least 1 millisecond before clearing PxSCTL.DET to 0h; this ensures that at least one COMRESET
|
|
|
|
|
// signal is sent over the interface. After clearing PxSCTL.DET to 0h, software should wait for
|
|
|
|
|
// communication to be re-established as indicated by PxSSTS.DET being set to 3h. Then software should
|
|
|
|
|
// write all 1s to the PxSERR register to clear any bits that were set as part of the port reset.
|
|
|
|
|
|
|
|
|
|
sctl.Status = StorPortReadRegisterUlong(AdapterExtension, &PortExtension->Port->SCTL);
|
|
|
|
|
sctl.DET = 1;
|
|
|
|
|
StorPortWriteRegisterUlong(AdapterExtension, &PortExtension->Port->SCTL, sctl.Status);
|
|
|
|
|
|
|
|
|
|
StorPortStallExecution(1000);
|
|
|
|
|
|
|
|
|
|
sctl.Status = StorPortReadRegisterUlong(AdapterExtension, &PortExtension->Port->SCTL);
|
|
|
|
|
sctl.DET = 0;
|
|
|
|
|
StorPortWriteRegisterUlong(AdapterExtension, &PortExtension->Port->SCTL, sctl.Status);
|
|
|
|
|
|
|
|
|
|
// Poll DET to verify if a device is attached to the port
|
|
|
|
|
index = 0;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
StorPortStallExecution(1000);
|
|
|
|
|
ssts.Status = StorPortReadRegisterUlong(AdapterExtension, &PortExtension->Port->SSTS);
|
|
|
|
|
|
|
|
|
|
index++;
|
|
|
|
|
if (ssts.DET != 0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while(index < 30);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ssts.Status = StorPortReadRegisterUlong(AdapterExtension, &PortExtension->Port->SSTS);
|
|
|
|
|
if (ssts.DET == 0x4)
|
|
|
|
|
{
|
|
|
|
|
// no device found
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DebugPrint("\tDET: %d %x %x\n", ssts.DET, PortExtension->Port->CMD, PortExtension->Port->SSTS);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}// -- AhciStartPort();
|
|
|
|
|
|
2016-06-02 14:43:56 +00:00
|
|
|
|
/**
|
2016-06-04 12:52:38 +00:00
|
|
|
|
* @name AhciHwInitialize
|
|
|
|
|
* @implemented
|
|
|
|
|
*
|
|
|
|
|
* initializes the HBA and finds all devices that are of interest to the miniport driver.
|
|
|
|
|
*
|
|
|
|
|
* @param adapterExtension
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
* return TRUE if intialization was successful
|
|
|
|
|
*/
|
2016-06-09 23:47:19 +00:00
|
|
|
|
BOOLEAN
|
|
|
|
|
AhciHwInitialize (
|
2016-06-10 08:27:20 +00:00
|
|
|
|
__in PVOID AdapterExtension
|
2016-06-09 23:47:19 +00:00
|
|
|
|
)
|
2016-06-04 12:52:38 +00:00
|
|
|
|
{
|
2016-07-04 19:01:07 +00:00
|
|
|
|
ULONG ghc, messageCount, status, cmd, index;
|
|
|
|
|
PAHCI_PORT_EXTENSION PortExtension;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
PAHCI_ADAPTER_EXTENSION adapterExtension;
|
2016-07-04 19:01:07 +00:00
|
|
|
|
AHCI_SERIAL_ATA_STATUS ssts;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
DebugPrint("AhciHwInitialize()\n");
|
2016-06-04 12:52:38 +00:00
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
adapterExtension = AdapterExtension;
|
2016-06-07 11:05:32 +00:00
|
|
|
|
adapterExtension->StateFlags.MessagePerPort = FALSE;
|
|
|
|
|
|
|
|
|
|
// First check what type of interrupt/synchronization device is using
|
|
|
|
|
ghc = StorPortReadRegisterUlong(adapterExtension, &adapterExtension->ABAR_Address->GHC);
|
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
// When set to ‘1’ by hardware, indicates that the HBA requested more than one MSI vector
|
|
|
|
|
// but has reverted to using the first vector only. When this bit is cleared to ‘0’,
|
|
|
|
|
// the HBA has not reverted to single MSI mode (i.e. hardware is already in single MSI mode,
|
|
|
|
|
// software has allocated the number of messages requested
|
2016-06-07 11:05:32 +00:00
|
|
|
|
if ((ghc & AHCI_Global_HBA_CONTROL_MRSM) == 0)
|
|
|
|
|
{
|
|
|
|
|
adapterExtension->StateFlags.MessagePerPort = TRUE;
|
2016-06-09 23:47:19 +00:00
|
|
|
|
DebugPrint("\tMultiple MSI based message not supported\n");
|
2016-06-07 11:05:32 +00:00
|
|
|
|
}
|
2016-06-04 12:52:38 +00:00
|
|
|
|
|
2016-07-04 19:01:07 +00:00
|
|
|
|
for (index = 0; index < adapterExtension->PortCount; index++)
|
|
|
|
|
{
|
|
|
|
|
if ((adapterExtension->PortImplemented & (0x1 << index)) != 0)
|
|
|
|
|
{
|
|
|
|
|
PortExtension = &adapterExtension->PortExtension[index];
|
|
|
|
|
PortExtension->IsActive = AhciStartPort(PortExtension);
|
|
|
|
|
if (PortExtension->IsActive == FALSE)
|
|
|
|
|
{
|
|
|
|
|
DebugPrint("\tPort Disabled: %d\n", index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-04 12:52:38 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}// -- AhciHwInitialize();
|
|
|
|
|
|
2016-06-30 16:04:50 +00:00
|
|
|
|
/**
|
|
|
|
|
* @name AhciCompleteIssuedSrb
|
|
|
|
|
* @implemented
|
|
|
|
|
*
|
|
|
|
|
* Complete issued Srbs
|
|
|
|
|
*
|
|
|
|
|
* @param PortExtension
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
AhciCompleteIssuedSrb (
|
|
|
|
|
__in PAHCI_PORT_EXTENSION PortExtension,
|
|
|
|
|
__in ULONG CommandsToComplete
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
ULONG NCS, i;
|
|
|
|
|
PSCSI_REQUEST_BLOCK Srb;
|
|
|
|
|
PAHCI_SRB_EXTENSION SrbExtension;
|
|
|
|
|
PAHCI_ADAPTER_EXTENSION AdapterExtension;
|
|
|
|
|
PAHCI_COMPLETION_ROUTINE CompletionRoutine;
|
|
|
|
|
|
|
|
|
|
DebugPrint("AhciCompleteIssuedSrb()\n");
|
|
|
|
|
|
|
|
|
|
NT_ASSERT(CommandsToComplete != 0);
|
|
|
|
|
|
|
|
|
|
DebugPrint("\tCompleted Commands: %d\n", CommandsToComplete);
|
|
|
|
|
|
|
|
|
|
AdapterExtension = PortExtension->AdapterExtension;
|
|
|
|
|
NCS = AHCI_Global_Port_CAP_NCS(AdapterExtension->CAP);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < NCS; i++)
|
|
|
|
|
{
|
|
|
|
|
if (((1 << i) & CommandsToComplete) != 0)
|
|
|
|
|
{
|
2016-07-04 19:01:07 +00:00
|
|
|
|
Srb = PortExtension->Slot[i];
|
2016-06-30 16:04:50 +00:00
|
|
|
|
NT_ASSERT(Srb != NULL);
|
|
|
|
|
|
|
|
|
|
if (Srb->SrbStatus == SRB_STATUS_PENDING)
|
|
|
|
|
{
|
|
|
|
|
Srb->SrbStatus = SRB_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrbExtension = GetSrbExtension(Srb);
|
|
|
|
|
CompletionRoutine = SrbExtension->CompletionRoutine;
|
|
|
|
|
|
|
|
|
|
if (CompletionRoutine != NULL)
|
|
|
|
|
{
|
|
|
|
|
// now it's completion routine responsibility to set SrbStatus
|
|
|
|
|
CompletionRoutine(AdapterExtension, PortExtension, Srb);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Srb->SrbStatus = SRB_STATUS_SUCCESS;
|
|
|
|
|
StorPortNotification(RequestComplete, AdapterExtension, Srb);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}// -- AhciCompleteIssuedSrb();
|
|
|
|
|
|
2016-06-07 18:06:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* @name AhciInterruptHandler
|
2016-06-15 17:07:26 +00:00
|
|
|
|
* @not_implemented
|
2016-06-07 18:06:51 +00:00
|
|
|
|
*
|
2016-06-10 08:27:20 +00:00
|
|
|
|
* Interrupt Handler for PortExtension
|
2016-06-07 18:06:51 +00:00
|
|
|
|
*
|
2016-06-10 08:27:20 +00:00
|
|
|
|
* @param PortExtension
|
2016-06-07 18:06:51 +00:00
|
|
|
|
*
|
|
|
|
|
*/
|
2016-06-16 17:02:55 +00:00
|
|
|
|
VOID
|
2016-06-09 23:47:19 +00:00
|
|
|
|
AhciInterruptHandler (
|
2016-06-10 08:27:20 +00:00
|
|
|
|
__in PAHCI_PORT_EXTENSION PortExtension
|
2016-06-09 23:47:19 +00:00
|
|
|
|
)
|
2016-06-07 18:06:51 +00:00
|
|
|
|
{
|
2016-06-27 12:58:04 +00:00
|
|
|
|
ULONG is, ci, sact, outstanding;
|
2016-06-16 17:02:55 +00:00
|
|
|
|
AHCI_INTERRUPT_STATUS PxIS;
|
|
|
|
|
AHCI_INTERRUPT_STATUS PxISMasked;
|
|
|
|
|
PAHCI_ADAPTER_EXTENSION AdapterExtension;
|
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
DebugPrint("AhciInterruptHandler()\n");
|
2016-06-10 08:27:20 +00:00
|
|
|
|
DebugPrint("\tPort Number: %d\n", PortExtension->PortNumber);
|
2016-06-07 18:06:51 +00:00
|
|
|
|
|
2016-06-16 17:02:55 +00:00
|
|
|
|
AdapterExtension = PortExtension->AdapterExtension;
|
|
|
|
|
NT_ASSERT(IsPortValid(AdapterExtension, PortExtension->PortNumber));
|
|
|
|
|
|
|
|
|
|
// 5.5.3
|
|
|
|
|
// 1. Software determines the cause of the interrupt by reading the PxIS register.
|
|
|
|
|
// It is possible for multiple bits to be set
|
|
|
|
|
// 2. Software clears appropriate bits in the PxIS register corresponding to the cause of the interrupt.
|
|
|
|
|
// 3. Software clears the interrupt bit in IS.IPS corresponding to the port.
|
|
|
|
|
// 4. If executing non-queued commands, software reads the PxCI register, and compares the current value to
|
|
|
|
|
// the list of commands previously issued by software that are still outstanding.
|
|
|
|
|
// If executing native queued commands, software reads the PxSACT register and compares the current
|
|
|
|
|
// value to the list of commands previously issued by software.
|
|
|
|
|
// Software completes with success any outstanding command whose corresponding bit has been cleared in
|
|
|
|
|
// the respective register. PxCI and PxSACT are volatile registers; software should only use their values
|
|
|
|
|
// to determine commands that have completed, not to determine which commands have previously been issued.
|
|
|
|
|
// 5. If there were errors, noted in the PxIS register, software performs error recovery actions (see section 6.2.2).
|
|
|
|
|
PxISMasked.Status = 0;
|
|
|
|
|
PxIS.Status = StorPortReadRegisterUlong(AdapterExtension, &PortExtension->Port->IS);
|
|
|
|
|
|
|
|
|
|
// 6.2.2
|
|
|
|
|
// Fatal Error
|
|
|
|
|
// signified by the setting of PxIS.HBFS, PxIS.HBDS, PxIS.IFS, or PxIS.TFES
|
|
|
|
|
if (PxIS.HBFS || PxIS.HBDS || PxIS.IFS || PxIS.TFES)
|
|
|
|
|
{
|
|
|
|
|
// In this state, the HBA shall not issue any new commands nor acknowledge DMA Setup FISes to process
|
|
|
|
|
// any native command queuing commands. To recover, the port must be restarted
|
|
|
|
|
// To detect an error that requires software recovery actions to be performed,
|
|
|
|
|
// software should check whether any of the following status bits are set on an interrupt:
|
|
|
|
|
// PxIS.HBFS, PxIS.HBDS, PxIS.IFS, and PxIS.TFES. If any of these bits are set,
|
|
|
|
|
// software should perform the appropriate error recovery actions based on whether
|
|
|
|
|
// non-queued commands were being issued or native command queuing commands were being issued.
|
|
|
|
|
|
2016-06-22 16:08:45 +00:00
|
|
|
|
DebugPrint("\tFatal Error: %x\n", PxIS.Status);
|
2016-06-16 17:02:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Normal Command Completion
|
|
|
|
|
// 3.3.5
|
|
|
|
|
// A D2H Register FIS has been received with the ‘I’ bit set, and has been copied into system memory.
|
|
|
|
|
PxISMasked.DHRS = PxIS.DHRS;
|
|
|
|
|
// A PIO Setup FIS has been received with the ‘I’ bit set, it has been copied into system memory.
|
|
|
|
|
PxISMasked.PSS = PxIS.PSS;
|
|
|
|
|
// A DMA Setup FIS has been received with the ‘I’ bit set and has been copied into system memory.
|
|
|
|
|
PxISMasked.DSS = PxIS.DSS;
|
|
|
|
|
// A Set Device Bits FIS has been received with the ‘I’ bit set and has been copied into system memory/
|
|
|
|
|
PxISMasked.SDBS = PxIS.SDBS;
|
|
|
|
|
// A PRD with the ‘I’ bit set has transferred all of its data.
|
|
|
|
|
PxISMasked.DPS = PxIS.DPS;
|
|
|
|
|
|
|
|
|
|
if (PxISMasked.Status != 0)
|
|
|
|
|
{
|
|
|
|
|
StorPortWriteRegisterUlong(AdapterExtension, &PortExtension->Port->IS, PxISMasked.Status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 10.7.1.1
|
|
|
|
|
// Clear port interrupt
|
|
|
|
|
// It is set by the level of the virtual interrupt line being a set, and cleared by a write of ‘1’ from the software.
|
2016-06-27 12:58:04 +00:00
|
|
|
|
is = (1 << PortExtension->PortNumber);
|
|
|
|
|
StorPortWriteRegisterUlong(AdapterExtension, AdapterExtension->IS, is);
|
|
|
|
|
|
|
|
|
|
ci = StorPortReadRegisterUlong(AdapterExtension, &PortExtension->Port->CI);
|
|
|
|
|
sact = StorPortReadRegisterUlong(AdapterExtension, &PortExtension->Port->SACT);
|
|
|
|
|
|
|
|
|
|
outstanding = ci | sact; // NOTE: Including both non-NCQ and NCQ based commands
|
|
|
|
|
if ((PortExtension->CommandIssuedSlots & (~outstanding)) != 0)
|
|
|
|
|
{
|
2016-06-30 16:04:50 +00:00
|
|
|
|
AhciCompleteIssuedSrb(PortExtension, (PortExtension->CommandIssuedSlots & (~outstanding)));
|
2016-06-27 12:58:04 +00:00
|
|
|
|
PortExtension->CommandIssuedSlots &= outstanding;
|
|
|
|
|
}
|
2016-06-16 17:02:55 +00:00
|
|
|
|
|
|
|
|
|
return;
|
2016-06-07 18:06:51 +00:00
|
|
|
|
}// -- AhciInterruptHandler();
|
|
|
|
|
|
2016-06-04 12:52:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* @name AhciHwInterrupt
|
|
|
|
|
* @implemented
|
|
|
|
|
*
|
|
|
|
|
* The Storport driver calls the HwStorInterrupt routine after the HBA generates an interrupt request.
|
|
|
|
|
*
|
2016-06-16 21:14:03 +00:00
|
|
|
|
* @param AdapterExtension
|
2016-06-04 12:52:38 +00:00
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
* return TRUE Indicates that an interrupt was pending on adapter.
|
|
|
|
|
* return FALSE Indicates the interrupt was not ours.
|
|
|
|
|
*/
|
2016-06-09 23:47:19 +00:00
|
|
|
|
BOOLEAN
|
|
|
|
|
AhciHwInterrupt(
|
2016-06-16 21:14:03 +00:00
|
|
|
|
__in PAHCI_ADAPTER_EXTENSION AdapterExtension
|
2016-06-09 23:47:19 +00:00
|
|
|
|
)
|
2016-06-04 12:52:38 +00:00
|
|
|
|
{
|
2016-06-16 21:14:03 +00:00
|
|
|
|
ULONG portPending, nextPort, i, portCount;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
DebugPrint("AhciHwInterrupt()\n");
|
2016-06-04 12:52:38 +00:00
|
|
|
|
|
2016-06-16 21:14:03 +00:00
|
|
|
|
if (AdapterExtension->StateFlags.Removed)
|
2016-06-09 23:47:19 +00:00
|
|
|
|
{
|
2016-06-07 18:06:51 +00:00
|
|
|
|
return FALSE;
|
2016-06-09 23:47:19 +00:00
|
|
|
|
}
|
2016-06-07 18:06:51 +00:00
|
|
|
|
|
2016-06-16 21:14:03 +00:00
|
|
|
|
portPending = StorPortReadRegisterUlong(AdapterExtension, AdapterExtension->IS);
|
2016-06-07 18:06:51 +00:00
|
|
|
|
// we process interrupt for implemented ports only
|
2016-06-16 21:14:03 +00:00
|
|
|
|
portCount = AdapterExtension->PortCount;
|
|
|
|
|
portPending = portPending & AdapterExtension->PortImplemented;
|
2016-06-07 18:06:51 +00:00
|
|
|
|
|
|
|
|
|
if (portPending == 0)
|
2016-06-09 23:47:19 +00:00
|
|
|
|
{
|
2016-06-07 18:06:51 +00:00
|
|
|
|
return FALSE;
|
2016-06-09 23:47:19 +00:00
|
|
|
|
}
|
2016-06-07 18:06:51 +00:00
|
|
|
|
|
2016-06-16 21:14:03 +00:00
|
|
|
|
for (i = 1; i <= portCount; i++)
|
2016-06-07 18:06:51 +00:00
|
|
|
|
{
|
2016-06-16 21:14:03 +00:00
|
|
|
|
nextPort = (AdapterExtension->LastInterruptPort + i) % portCount;
|
2016-06-07 18:06:51 +00:00
|
|
|
|
|
|
|
|
|
if ((portPending & (0x1 << nextPort)) == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
2016-06-16 17:02:55 +00:00
|
|
|
|
NT_ASSERT(IsPortValid(AdapterExtension, nextPort));
|
|
|
|
|
|
2016-07-04 19:01:07 +00:00
|
|
|
|
if (nextPort == AdapterExtension->LastInterruptPort)
|
2016-06-09 23:47:19 +00:00
|
|
|
|
{
|
2016-06-07 18:06:51 +00:00
|
|
|
|
return FALSE;
|
2016-06-09 23:47:19 +00:00
|
|
|
|
}
|
2016-06-07 18:06:51 +00:00
|
|
|
|
|
2016-07-04 19:01:07 +00:00
|
|
|
|
if (AdapterExtension->PortExtension[nextPort].IsActive == FALSE)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 18:06:51 +00:00
|
|
|
|
// we can assign this interrupt to this port
|
2016-06-16 21:14:03 +00:00
|
|
|
|
AdapterExtension->LastInterruptPort = nextPort;
|
|
|
|
|
AhciInterruptHandler(&AdapterExtension->PortExtension[nextPort]);
|
2016-06-16 17:02:55 +00:00
|
|
|
|
|
|
|
|
|
// interrupt belongs to this device
|
|
|
|
|
// should always return TRUE
|
|
|
|
|
return TRUE;
|
2016-06-07 18:06:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 17:07:26 +00:00
|
|
|
|
DebugPrint("\tSomething went wrong");
|
2016-06-07 11:05:32 +00:00
|
|
|
|
return FALSE;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
}// -- AhciHwInterrupt();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @name AhciHwStartIo
|
2016-06-20 11:49:22 +00:00
|
|
|
|
* @not_implemented
|
2016-06-04 12:52:38 +00:00
|
|
|
|
*
|
|
|
|
|
* The Storport driver calls the HwStorStartIo routine one time for each incoming I/O request.
|
|
|
|
|
*
|
|
|
|
|
* @param adapterExtension
|
|
|
|
|
* @param Srb
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
* return TRUE if the request was accepted
|
|
|
|
|
* return FALSE if the request must be submitted later
|
|
|
|
|
*/
|
2016-06-09 23:47:19 +00:00
|
|
|
|
BOOLEAN
|
|
|
|
|
AhciHwStartIo (
|
2016-06-10 08:27:20 +00:00
|
|
|
|
__in PVOID AdapterExtension,
|
|
|
|
|
__in PSCSI_REQUEST_BLOCK Srb
|
2016-06-09 23:47:19 +00:00
|
|
|
|
)
|
2016-06-04 12:52:38 +00:00
|
|
|
|
{
|
2016-06-07 11:05:32 +00:00
|
|
|
|
UCHAR function, pathId;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
PAHCI_ADAPTER_EXTENSION adapterExtension;
|
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
DebugPrint("AhciHwStartIo()\n");
|
2016-06-04 12:52:38 +00:00
|
|
|
|
|
2016-06-07 11:05:32 +00:00
|
|
|
|
pathId = Srb->PathId;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
function = Srb->Function;
|
2016-06-09 23:47:19 +00:00
|
|
|
|
adapterExtension = AdapterExtension;
|
2016-06-07 11:05:32 +00:00
|
|
|
|
|
|
|
|
|
if (!IsPortValid(adapterExtension, pathId))
|
|
|
|
|
{
|
|
|
|
|
Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
|
|
|
|
|
StorPortNotification(RequestComplete, adapterExtension, Srb);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2016-06-04 12:52:38 +00:00
|
|
|
|
|
2016-06-07 11:05:32 +00:00
|
|
|
|
// https://msdn.microsoft.com/windows/hardware/drivers/storage/handling-srb-function-pnp
|
|
|
|
|
// If the function member of an SRB is set to SRB_FUNCTION_PNP,
|
|
|
|
|
// the SRB is a structure of type SCSI_PNP_REQUEST_BLOCK.
|
|
|
|
|
if (function == SRB_FUNCTION_PNP)
|
|
|
|
|
{
|
|
|
|
|
PSCSI_PNP_REQUEST_BLOCK pnpRequest;
|
|
|
|
|
|
|
|
|
|
pnpRequest = (PSCSI_PNP_REQUEST_BLOCK)Srb;
|
|
|
|
|
if ((pnpRequest->SrbPnPFlags & SRB_PNP_FLAGS_ADAPTER_REQUEST) != 0)
|
|
|
|
|
{
|
2016-06-09 23:47:19 +00:00
|
|
|
|
if ((pnpRequest->PnPAction == StorRemoveDevice) ||
|
|
|
|
|
(pnpRequest->PnPAction == StorSurpriseRemoval))
|
2016-06-07 11:05:32 +00:00
|
|
|
|
{
|
|
|
|
|
Srb->SrbStatus = SRB_STATUS_SUCCESS;
|
|
|
|
|
adapterExtension->StateFlags.Removed = 1;
|
2016-06-16 17:02:55 +00:00
|
|
|
|
DebugPrint("\tAdapter removed\n");
|
2016-06-07 11:05:32 +00:00
|
|
|
|
}
|
|
|
|
|
else if (pnpRequest->PnPAction == StorStopDevice)
|
|
|
|
|
{
|
|
|
|
|
Srb->SrbStatus = SRB_STATUS_SUCCESS;
|
2016-06-09 23:47:19 +00:00
|
|
|
|
DebugPrint("\tRequested to Stop the adapter\n");
|
2016-06-07 11:05:32 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2016-06-09 23:47:19 +00:00
|
|
|
|
{
|
2016-06-07 11:05:32 +00:00
|
|
|
|
Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
|
2016-06-09 23:47:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 11:05:32 +00:00
|
|
|
|
StorPortNotification(RequestComplete, adapterExtension, Srb);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (function == SRB_FUNCTION_EXECUTE_SCSI)
|
|
|
|
|
{
|
|
|
|
|
// https://msdn.microsoft.com/en-us/windows/hardware/drivers/storage/handling-srb-function-execute-scsi
|
|
|
|
|
// On receipt of an SRB_FUNCTION_EXECUTE_SCSI request, a miniport driver's HwScsiStartIo
|
|
|
|
|
// routine does the following:
|
|
|
|
|
//
|
|
|
|
|
// - Gets and/or sets up whatever context the miniport driver maintains in its device,
|
|
|
|
|
// logical unit, and/or SRB extensions
|
|
|
|
|
// For example, a miniport driver might set up a logical unit extension with pointers
|
|
|
|
|
// to the SRB itself and the SRB DataBuffer pointer, the SRB DataTransferLength value,
|
|
|
|
|
// and a driver-defined value (or CDB SCSIOP_XXX value) indicating the operation to be
|
|
|
|
|
// carried out on the HBA.
|
|
|
|
|
//
|
|
|
|
|
// - Calls an internal routine to program the HBA, as partially directed by the SrbFlags,
|
|
|
|
|
// for the requested operation
|
|
|
|
|
// For a device I/O operation, such an internal routine generally selects the target device
|
|
|
|
|
// and sends the CDB over the bus to the target logical unit.
|
|
|
|
|
if (Srb->CdbLength > 0)
|
|
|
|
|
{
|
|
|
|
|
PCDB cdb = (PCDB)&Srb->Cdb;
|
|
|
|
|
if (cdb->CDB10.OperationCode == SCSIOP_INQUIRY)
|
|
|
|
|
{
|
2016-06-07 18:06:51 +00:00
|
|
|
|
Srb->SrbStatus = DeviceInquiryRequest(adapterExtension, Srb, cdb);
|
2016-06-16 21:14:03 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
|
2016-06-07 11:05:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Srb->SrbStatus = SRB_STATUS_BAD_FUNCTION;
|
|
|
|
|
}
|
2016-06-16 21:14:03 +00:00
|
|
|
|
|
|
|
|
|
StorPortNotification(RequestComplete, adapterExtension, Srb);
|
|
|
|
|
return TRUE;
|
2016-06-07 11:05:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-16 21:14:03 +00:00
|
|
|
|
DebugPrint("\tUnknown function code recieved: %x\n", function);
|
2016-06-07 11:05:32 +00:00
|
|
|
|
Srb->SrbStatus = SRB_STATUS_BAD_FUNCTION;
|
|
|
|
|
StorPortNotification(RequestComplete, adapterExtension, Srb);
|
2016-06-04 12:52:38 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}// -- AhciHwStartIo();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @name AhciHwResetBus
|
2016-06-09 23:47:19 +00:00
|
|
|
|
* @not_implemented
|
2016-06-04 12:52:38 +00:00
|
|
|
|
*
|
|
|
|
|
* The HwStorResetBus routine is called by the port driver to clear error conditions.
|
|
|
|
|
*
|
|
|
|
|
* @param adapterExtension
|
|
|
|
|
* @param PathId
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
* return TRUE if bus was successfully reset
|
|
|
|
|
*/
|
2016-06-09 23:47:19 +00:00
|
|
|
|
BOOLEAN
|
|
|
|
|
AhciHwResetBus (
|
2016-06-10 08:27:20 +00:00
|
|
|
|
__in PVOID AdapterExtension,
|
|
|
|
|
__in ULONG PathId
|
2016-06-09 23:47:19 +00:00
|
|
|
|
)
|
2016-06-04 12:52:38 +00:00
|
|
|
|
{
|
2016-06-16 17:02:55 +00:00
|
|
|
|
STOR_LOCK_HANDLE lockhandle;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
PAHCI_ADAPTER_EXTENSION adapterExtension;
|
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
DebugPrint("AhciHwResetBus()\n");
|
2016-06-04 12:52:38 +00:00
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
adapterExtension = AdapterExtension;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
|
2016-06-15 17:07:26 +00:00
|
|
|
|
if (IsPortValid(AdapterExtension, PathId))
|
|
|
|
|
{
|
2016-06-16 17:02:55 +00:00
|
|
|
|
AhciZeroMemory(&lockhandle, sizeof(lockhandle));
|
|
|
|
|
|
|
|
|
|
// Acquire Lock
|
|
|
|
|
StorPortAcquireSpinLock(AdapterExtension, InterruptLock, NULL, &lockhandle);
|
|
|
|
|
|
|
|
|
|
// TODO: Perform port reset
|
|
|
|
|
|
|
|
|
|
// Release lock
|
|
|
|
|
StorPortReleaseSpinLock(AdapterExtension, &lockhandle);
|
2016-06-15 17:07:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 18:06:51 +00:00
|
|
|
|
return FALSE;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
}// -- AhciHwResetBus();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @name AhciHwFindAdapter
|
2016-06-02 14:43:56 +00:00
|
|
|
|
* @implemented
|
|
|
|
|
*
|
|
|
|
|
* The HwStorFindAdapter routine uses the supplied configuration to determine whether a specific
|
|
|
|
|
* HBA is supported and, if it is, to return configuration information about that adapter.
|
|
|
|
|
*
|
|
|
|
|
* 10.1 Platform Communication
|
|
|
|
|
* http://www.intel.in/content/dam/www/public/us/en/documents/technical-specifications/serial-ata-ahci-spec-rev1_2.pdf
|
|
|
|
|
|
|
|
|
|
* @param DeviceExtension
|
|
|
|
|
* @param HwContext
|
|
|
|
|
* @param BusInformation
|
|
|
|
|
* @param ArgumentString
|
|
|
|
|
* @param ConfigInfo
|
|
|
|
|
* @param Reserved3
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
* SP_RETURN_FOUND
|
|
|
|
|
* Indicates that a supported HBA was found and that the HBA-relevant configuration information was successfully determined and set in the PORT_CONFIGURATION_INFORMATION structure.
|
|
|
|
|
*
|
|
|
|
|
* SP_RETURN_ERROR
|
|
|
|
|
* Indicates that an HBA was found but there was an error obtaining the configuration information. If possible, such an error should be logged with StorPortLogError.
|
|
|
|
|
*
|
|
|
|
|
* SP_RETURN_BAD_CONFIG
|
|
|
|
|
* Indicates that the supplied configuration information was invalid for the adapter.
|
|
|
|
|
*
|
|
|
|
|
* SP_RETURN_NOT_FOUND
|
|
|
|
|
* Indicates that no supported HBA was found for the supplied configuration information.
|
|
|
|
|
*
|
|
|
|
|
* @remarks Called by Storport.
|
|
|
|
|
*/
|
2016-06-09 23:47:19 +00:00
|
|
|
|
ULONG
|
|
|
|
|
AhciHwFindAdapter (
|
2016-06-10 08:27:20 +00:00
|
|
|
|
__in PVOID AdapterExtension,
|
|
|
|
|
__in PVOID HwContext,
|
|
|
|
|
__in PVOID BusInformation,
|
|
|
|
|
__in PVOID ArgumentString,
|
|
|
|
|
__inout PPORT_CONFIGURATION_INFORMATION ConfigInfo,
|
|
|
|
|
__in PBOOLEAN Reserved3
|
2016-06-09 23:47:19 +00:00
|
|
|
|
)
|
2016-06-02 14:13:06 +00:00
|
|
|
|
{
|
2016-06-02 14:43:56 +00:00
|
|
|
|
ULONG ghc;
|
2016-06-03 15:54:21 +00:00
|
|
|
|
ULONG index;
|
2016-06-02 14:43:56 +00:00
|
|
|
|
ULONG portCount, portImplemented;
|
|
|
|
|
ULONG pci_cfg_len;
|
2016-06-09 23:47:19 +00:00
|
|
|
|
UCHAR pci_cfg_buf[sizeof(PCI_COMMON_CONFIG)];
|
|
|
|
|
PACCESS_RANGE accessRange;
|
2016-06-07 11:05:32 +00:00
|
|
|
|
|
2016-06-02 14:43:56 +00:00
|
|
|
|
PAHCI_MEMORY_REGISTERS abar;
|
|
|
|
|
PPCI_COMMON_CONFIG pciConfigData;
|
|
|
|
|
PAHCI_ADAPTER_EXTENSION adapterExtension;
|
2016-06-02 14:13:06 +00:00
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
DebugPrint("AhciHwFindAdapter()\n");
|
2016-06-04 12:52:38 +00:00
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
adapterExtension = AdapterExtension;
|
2016-06-02 14:43:56 +00:00
|
|
|
|
adapterExtension->SlotNumber = ConfigInfo->SlotNumber;
|
|
|
|
|
adapterExtension->SystemIoBusNumber = ConfigInfo->SystemIoBusNumber;
|
2016-06-07 11:05:32 +00:00
|
|
|
|
|
2016-06-02 14:43:56 +00:00
|
|
|
|
// get PCI configuration header
|
|
|
|
|
pci_cfg_len = StorPortGetBusData(
|
|
|
|
|
adapterExtension,
|
|
|
|
|
PCIConfiguration,
|
|
|
|
|
adapterExtension->SystemIoBusNumber,
|
|
|
|
|
adapterExtension->SlotNumber,
|
2016-06-09 23:47:19 +00:00
|
|
|
|
pci_cfg_buf,
|
|
|
|
|
sizeof(PCI_COMMON_CONFIG));
|
2016-06-02 14:43:56 +00:00
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
if (pci_cfg_len != sizeof(PCI_COMMON_CONFIG))
|
|
|
|
|
{
|
|
|
|
|
DebugPrint("\tpci_cfg_len != %d :: %d", sizeof(PCI_COMMON_CONFIG), pci_cfg_len);
|
2016-06-02 14:43:56 +00:00
|
|
|
|
return SP_RETURN_ERROR;//Not a valid device at the given bus number
|
2016-06-04 12:52:38 +00:00
|
|
|
|
}
|
2016-06-02 14:43:56 +00:00
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
pciConfigData = pci_cfg_buf;
|
2016-06-02 14:43:56 +00:00
|
|
|
|
adapterExtension->VendorID = pciConfigData->VendorID;
|
|
|
|
|
adapterExtension->DeviceID = pciConfigData->DeviceID;
|
|
|
|
|
adapterExtension->RevisionID = pciConfigData->RevisionID;
|
|
|
|
|
// The last PCI base address register (BAR[5], header offset 0x24) points to the AHCI base memory, it’s called ABAR (AHCI Base Memory Register).
|
|
|
|
|
adapterExtension->AhciBaseAddress = pciConfigData->u.type0.BaseAddresses[5] & (0xFFFFFFF0);
|
|
|
|
|
|
2016-06-10 08:27:20 +00:00
|
|
|
|
DebugPrint("\tVendorID:%d DeviceID:%d RevisionID:%d\n", adapterExtension->VendorID,
|
|
|
|
|
adapterExtension->DeviceID,
|
|
|
|
|
adapterExtension->RevisionID);
|
2016-06-04 12:52:38 +00:00
|
|
|
|
|
2016-06-02 14:43:56 +00:00
|
|
|
|
// 2.1.11
|
|
|
|
|
abar = NULL;
|
|
|
|
|
if (ConfigInfo->NumberOfAccessRanges > 0)
|
|
|
|
|
{
|
2016-06-03 15:54:21 +00:00
|
|
|
|
for (index = 0; index < ConfigInfo->NumberOfAccessRanges; index++)
|
2016-06-02 14:43:56 +00:00
|
|
|
|
{
|
2016-06-09 23:47:19 +00:00
|
|
|
|
accessRange = *ConfigInfo->AccessRanges;
|
|
|
|
|
if (accessRange[index].RangeStart.QuadPart == adapterExtension->AhciBaseAddress)
|
2016-06-02 14:43:56 +00:00
|
|
|
|
{
|
2016-06-15 17:07:26 +00:00
|
|
|
|
abar = StorPortGetDeviceBase(adapterExtension,
|
|
|
|
|
ConfigInfo->AdapterInterfaceType,
|
|
|
|
|
ConfigInfo->SystemIoBusNumber,
|
|
|
|
|
accessRange[index].RangeStart,
|
|
|
|
|
accessRange[index].RangeLength,
|
|
|
|
|
!accessRange[index].RangeInMemory);
|
2016-06-02 14:43:56 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
if (abar == NULL)
|
|
|
|
|
{
|
|
|
|
|
DebugPrint("\tabar == NULL\n");
|
2016-06-02 14:43:56 +00:00
|
|
|
|
return SP_RETURN_ERROR; // corrupted information supplied
|
2016-06-04 12:52:38 +00:00
|
|
|
|
}
|
2016-06-02 14:43:56 +00:00
|
|
|
|
|
|
|
|
|
adapterExtension->ABAR_Address = abar;
|
|
|
|
|
adapterExtension->CAP = StorPortReadRegisterUlong(adapterExtension, &abar->CAP);
|
|
|
|
|
adapterExtension->CAP2 = StorPortReadRegisterUlong(adapterExtension, &abar->CAP2);
|
|
|
|
|
adapterExtension->Version = StorPortReadRegisterUlong(adapterExtension, &abar->VS);
|
2016-06-07 18:06:51 +00:00
|
|
|
|
adapterExtension->LastInterruptPort = -1;
|
2016-06-02 14:43:56 +00:00
|
|
|
|
|
|
|
|
|
// 10.1.2
|
|
|
|
|
// 1. Indicate that system software is AHCI aware by setting GHC.AE to ‘1’.
|
2016-06-03 15:54:21 +00:00
|
|
|
|
// 3.1.2 -- AE bit is read-write only if CAP.SAM is '0'
|
2016-06-02 14:43:56 +00:00
|
|
|
|
ghc = StorPortReadRegisterUlong(adapterExtension, &abar->GHC);
|
|
|
|
|
// AE := Highest Significant bit of GHC
|
2016-06-20 11:49:22 +00:00
|
|
|
|
if ((ghc & AHCI_Global_HBA_CONTROL_AE) != 0)// Hmm, controller was already in power state
|
2016-06-02 14:43:56 +00:00
|
|
|
|
{
|
2016-06-07 18:06:51 +00:00
|
|
|
|
// reset controller to have it in known state
|
2016-06-09 23:47:19 +00:00
|
|
|
|
DebugPrint("\tAE Already set, Reset()\n");
|
2016-06-10 08:27:20 +00:00
|
|
|
|
if (!AhciAdapterReset(adapterExtension))
|
|
|
|
|
{
|
2016-06-09 23:47:19 +00:00
|
|
|
|
DebugPrint("\tReset Failed!\n");
|
2016-06-02 14:43:56 +00:00
|
|
|
|
return SP_RETURN_ERROR;// reset failed
|
2016-06-04 12:52:38 +00:00
|
|
|
|
}
|
2016-06-02 14:43:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 11:05:32 +00:00
|
|
|
|
ghc = AHCI_Global_HBA_CONTROL_AE;// only AE=1
|
2016-07-04 19:01:07 +00:00
|
|
|
|
// tell the controller that we know about AHCI
|
2016-06-02 14:43:56 +00:00
|
|
|
|
StorPortWriteRegisterUlong(adapterExtension, &abar->GHC, ghc);
|
|
|
|
|
|
2016-06-07 11:05:32 +00:00
|
|
|
|
adapterExtension->IS = &abar->IS;
|
2016-06-02 14:43:56 +00:00
|
|
|
|
adapterExtension->PortImplemented = StorPortReadRegisterUlong(adapterExtension, &abar->PI);
|
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
if (adapterExtension->PortImplemented == 0)
|
|
|
|
|
{
|
|
|
|
|
DebugPrint("\tadapterExtension->PortImplemented == 0\n");
|
2016-06-02 14:43:56 +00:00
|
|
|
|
return SP_RETURN_ERROR;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
}
|
2016-06-02 14:43:56 +00:00
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
ConfigInfo->MaximumTransferLength = MAXIMUM_TRANSFER_LENGTH;//128 KB
|
2016-06-02 14:43:56 +00:00
|
|
|
|
ConfigInfo->NumberOfPhysicalBreaks = 0x21;
|
|
|
|
|
ConfigInfo->MaximumNumberOfTargets = 1;
|
|
|
|
|
ConfigInfo->MaximumNumberOfLogicalUnits = 1;
|
|
|
|
|
ConfigInfo->ResetTargetSupported = TRUE;
|
2016-06-07 11:05:32 +00:00
|
|
|
|
ConfigInfo->NumberOfBuses = MAXIMUM_AHCI_PORT_COUNT;
|
2016-06-02 14:43:56 +00:00
|
|
|
|
ConfigInfo->SynchronizationModel = StorSynchronizeFullDuplex;
|
|
|
|
|
ConfigInfo->ScatterGather = TRUE;
|
|
|
|
|
|
2016-06-03 15:54:21 +00:00
|
|
|
|
// allocate necessary resource for each port
|
2016-06-09 23:47:19 +00:00
|
|
|
|
if (!AhciAllocateResourceForAdapter(adapterExtension, ConfigInfo))
|
|
|
|
|
{
|
|
|
|
|
DebugPrint("\tAhciAllocateResourceForAdapter() == FALSE\n");
|
2016-06-03 15:54:21 +00:00
|
|
|
|
return SP_RETURN_ERROR;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
}
|
2016-06-03 15:54:21 +00:00
|
|
|
|
|
2016-06-16 21:14:03 +00:00
|
|
|
|
for (index = 0; index < adapterExtension->PortCount; index++)
|
2016-06-03 15:54:21 +00:00
|
|
|
|
{
|
2016-06-20 11:49:22 +00:00
|
|
|
|
if ((adapterExtension->PortImplemented & (0x1 << index)) != 0)
|
2016-06-05 12:40:49 +00:00
|
|
|
|
AhciPortInitialize(&adapterExtension->PortExtension[index]);
|
2016-06-03 15:54:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-04 19:01:07 +00:00
|
|
|
|
// Turn IE -- Interrupt Enabled
|
|
|
|
|
ghc = StorPortReadRegisterUlong(adapterExtension, &abar->GHC);
|
|
|
|
|
ghc |= AHCI_Global_HBA_CONTROL_IE;
|
|
|
|
|
StorPortWriteRegisterUlong(adapterExtension, &abar->GHC, ghc);
|
|
|
|
|
|
2016-06-02 14:43:56 +00:00
|
|
|
|
return SP_RETURN_FOUND;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
}// -- AhciHwFindAdapter();
|
2016-06-02 14:43:56 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @name DriverEntry
|
|
|
|
|
* @implemented
|
|
|
|
|
*
|
|
|
|
|
* Initial Entrypoint for storahci miniport driver
|
|
|
|
|
*
|
|
|
|
|
* @param DriverObject
|
|
|
|
|
* @param RegistryPath
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
* NT_STATUS in case of driver loaded successfully.
|
|
|
|
|
*/
|
2016-06-09 23:47:19 +00:00
|
|
|
|
ULONG
|
|
|
|
|
DriverEntry (
|
2016-06-10 08:27:20 +00:00
|
|
|
|
__in PVOID DriverObject,
|
|
|
|
|
__in PVOID RegistryPath
|
2016-06-09 23:47:19 +00:00
|
|
|
|
)
|
2016-06-02 14:13:06 +00:00
|
|
|
|
{
|
2016-06-02 14:43:56 +00:00
|
|
|
|
HW_INITIALIZATION_DATA hwInitializationData;
|
|
|
|
|
ULONG i, status;
|
2016-06-02 14:13:06 +00:00
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
DebugPrint("Storahci Loaded\n");
|
2016-06-02 14:13:06 +00:00
|
|
|
|
|
2016-06-02 14:43:56 +00:00
|
|
|
|
// initialize the hardware data structure
|
2016-06-09 23:47:19 +00:00
|
|
|
|
AhciZeroMemory(&hwInitializationData, sizeof(HW_INITIALIZATION_DATA));
|
2016-06-02 14:13:06 +00:00
|
|
|
|
|
2016-06-02 14:43:56 +00:00
|
|
|
|
// set size of hardware initialization structure
|
|
|
|
|
hwInitializationData.HwInitializationDataSize = sizeof(HW_INITIALIZATION_DATA);
|
2016-06-02 14:13:06 +00:00
|
|
|
|
|
2016-06-02 14:43:56 +00:00
|
|
|
|
// identity required miniport entry point routines
|
2016-06-04 12:52:38 +00:00
|
|
|
|
hwInitializationData.HwStartIo = AhciHwStartIo;
|
|
|
|
|
hwInitializationData.HwResetBus = AhciHwResetBus;
|
|
|
|
|
hwInitializationData.HwInterrupt = AhciHwInterrupt;
|
|
|
|
|
hwInitializationData.HwInitialize = AhciHwInitialize;
|
|
|
|
|
hwInitializationData.HwFindAdapter = AhciHwFindAdapter;
|
2016-06-02 14:13:06 +00:00
|
|
|
|
|
2016-06-02 14:43:56 +00:00
|
|
|
|
// adapter specific information
|
|
|
|
|
hwInitializationData.NeedPhysicalAddresses = TRUE;
|
|
|
|
|
hwInitializationData.TaggedQueuing = TRUE;
|
|
|
|
|
hwInitializationData.AutoRequestSense = TRUE;
|
|
|
|
|
hwInitializationData.MultipleRequestPerLu = TRUE;
|
2016-06-02 14:13:06 +00:00
|
|
|
|
|
2016-06-02 14:43:56 +00:00
|
|
|
|
hwInitializationData.NumberOfAccessRanges = 6;
|
|
|
|
|
hwInitializationData.AdapterInterfaceType = PCIBus;
|
|
|
|
|
hwInitializationData.MapBuffers = STOR_MAP_NON_READ_WRITE_BUFFERS;
|
2016-06-02 14:13:06 +00:00
|
|
|
|
|
2016-06-02 14:43:56 +00:00
|
|
|
|
// set required extension sizes
|
|
|
|
|
hwInitializationData.SrbExtensionSize = sizeof(AHCI_SRB_EXTENSION);
|
|
|
|
|
hwInitializationData.DeviceExtensionSize = sizeof(AHCI_ADAPTER_EXTENSION);
|
2016-06-07 11:05:32 +00:00
|
|
|
|
|
2016-06-02 14:43:56 +00:00
|
|
|
|
// register our hw init data
|
2016-06-15 17:07:26 +00:00
|
|
|
|
status = StorPortInitialize(DriverObject,
|
|
|
|
|
RegistryPath,
|
|
|
|
|
&hwInitializationData,
|
|
|
|
|
NULL);
|
2016-06-07 11:05:32 +00:00
|
|
|
|
|
2016-07-04 19:01:07 +00:00
|
|
|
|
DebugPrint("\tstatus: %x\n", status);
|
2016-06-02 14:13:06 +00:00
|
|
|
|
return status;
|
|
|
|
|
}// -- DriverEntry();
|
|
|
|
|
|
2016-06-16 17:02:55 +00:00
|
|
|
|
/**
|
2016-06-20 11:49:22 +00:00
|
|
|
|
* @name AhciATA_CFIS
|
2016-06-27 12:58:04 +00:00
|
|
|
|
* @implemented
|
2016-06-20 11:49:22 +00:00
|
|
|
|
*
|
|
|
|
|
* create ATA CFIS from Srb
|
|
|
|
|
*
|
|
|
|
|
* @param PortExtension
|
|
|
|
|
* @param Srb
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
AhciATA_CFIS (
|
|
|
|
|
__in PAHCI_PORT_EXTENSION PortExtension,
|
|
|
|
|
__in PAHCI_SRB_EXTENSION SrbExtension
|
|
|
|
|
)
|
|
|
|
|
{
|
2016-06-27 12:58:04 +00:00
|
|
|
|
PAHCI_COMMAND_TABLE cmdTable;
|
|
|
|
|
|
2016-06-20 11:49:22 +00:00
|
|
|
|
DebugPrint("AhciATA_CFIS()\n");
|
|
|
|
|
|
2016-06-27 12:58:04 +00:00
|
|
|
|
cmdTable = (PAHCI_COMMAND_TABLE)SrbExtension;
|
|
|
|
|
|
|
|
|
|
NT_ASSERT(sizeof(cmdTable->CFIS) == 64);
|
|
|
|
|
|
|
|
|
|
AhciZeroMemory(&cmdTable->CFIS, sizeof(cmdTable->CFIS));
|
|
|
|
|
|
|
|
|
|
cmdTable->CFIS[AHCI_ATA_CFIS_FisType] = 0x27; // FIS Type
|
|
|
|
|
cmdTable->CFIS[AHCI_ATA_CFIS_PMPort_C] = (1 << 7); // PM Port & C
|
|
|
|
|
cmdTable->CFIS[AHCI_ATA_CFIS_CommandReg] = SrbExtension->CommandReg;
|
|
|
|
|
|
|
|
|
|
cmdTable->CFIS[AHCI_ATA_CFIS_FeaturesLow] = SrbExtension->FeaturesLow;
|
|
|
|
|
cmdTable->CFIS[AHCI_ATA_CFIS_LBA0] = SrbExtension->LBA0;
|
|
|
|
|
cmdTable->CFIS[AHCI_ATA_CFIS_LBA1] = SrbExtension->LBA1;
|
|
|
|
|
cmdTable->CFIS[AHCI_ATA_CFIS_LBA2] = SrbExtension->LBA2;
|
|
|
|
|
cmdTable->CFIS[AHCI_ATA_CFIS_Device] = SrbExtension->Device;
|
|
|
|
|
cmdTable->CFIS[AHCI_ATA_CFIS_LBA3] = SrbExtension->LBA3;
|
|
|
|
|
cmdTable->CFIS[AHCI_ATA_CFIS_LBA4] = SrbExtension->LBA4;
|
|
|
|
|
cmdTable->CFIS[AHCI_ATA_CFIS_LBA5] = SrbExtension->LBA5;
|
|
|
|
|
cmdTable->CFIS[AHCI_ATA_CFIS_FeaturesHigh] = SrbExtension->FeaturesHigh;
|
|
|
|
|
cmdTable->CFIS[AHCI_ATA_CFIS_SectorCountLow] = SrbExtension->SectorCountLow;
|
|
|
|
|
cmdTable->CFIS[AHCI_ATA_CFIS_SectorCountHigh] = SrbExtension->SectorCountHigh;
|
|
|
|
|
|
|
|
|
|
return;
|
2016-06-20 11:49:22 +00:00
|
|
|
|
}// -- AhciATA_CFIS();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @name AhciATAPI_CFIS
|
2016-06-16 17:02:55 +00:00
|
|
|
|
* @not_implemented
|
|
|
|
|
*
|
2016-06-20 11:49:22 +00:00
|
|
|
|
* create ATAPI CFIS from Srb
|
|
|
|
|
*
|
|
|
|
|
* @param PortExtension
|
|
|
|
|
* @param Srb
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
AhciATAPI_CFIS (
|
|
|
|
|
__in PAHCI_PORT_EXTENSION PortExtension,
|
|
|
|
|
__in PAHCI_SRB_EXTENSION SrbExtension
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
DebugPrint("AhciATAPI_CFIS()\n");
|
|
|
|
|
|
|
|
|
|
}// -- AhciATAPI_CFIS();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @name AhciBuild_PRDT
|
2016-06-22 16:08:45 +00:00
|
|
|
|
* @implemented
|
2016-06-20 11:49:22 +00:00
|
|
|
|
*
|
|
|
|
|
* Build PRDT for data transfer
|
|
|
|
|
*
|
|
|
|
|
* @param PortExtension
|
|
|
|
|
* @param Srb
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
* Return number of entries in PRDT.
|
|
|
|
|
*/
|
|
|
|
|
ULONG
|
|
|
|
|
AhciBuild_PRDT (
|
|
|
|
|
__in PAHCI_PORT_EXTENSION PortExtension,
|
|
|
|
|
__in PAHCI_SRB_EXTENSION SrbExtension
|
|
|
|
|
)
|
|
|
|
|
{
|
2016-06-22 16:08:45 +00:00
|
|
|
|
ULONG index;
|
|
|
|
|
PAHCI_COMMAND_TABLE cmdTable;
|
|
|
|
|
PLOCAL_SCATTER_GATHER_LIST sgl;
|
|
|
|
|
PAHCI_ADAPTER_EXTENSION AdapterExtension;
|
|
|
|
|
|
2016-06-20 11:49:22 +00:00
|
|
|
|
DebugPrint("AhciBuild_PRDT()\n");
|
|
|
|
|
|
2016-06-22 16:08:45 +00:00
|
|
|
|
sgl = &SrbExtension->Sgl;
|
|
|
|
|
cmdTable = (PAHCI_COMMAND_TABLE)SrbExtension;
|
|
|
|
|
AdapterExtension = PortExtension->AdapterExtension;
|
|
|
|
|
|
|
|
|
|
NT_ASSERT(sgl != NULL);
|
|
|
|
|
NT_ASSERT(sgl->NumberOfElements < MAXIMUM_AHCI_PRDT_ENTRIES);
|
|
|
|
|
|
|
|
|
|
for (index = 0; index < sgl->NumberOfElements; index++)
|
|
|
|
|
{
|
|
|
|
|
NT_ASSERT(sgl->List[index].Length <= MAXIMUM_TRANSFER_LENGTH);
|
|
|
|
|
|
|
|
|
|
cmdTable->PRDT[index].DBA = sgl->List[index].PhysicalAddress.LowPart;
|
|
|
|
|
if (IsAdapterCAPS64(AdapterExtension->CAP))
|
|
|
|
|
{
|
|
|
|
|
cmdTable->PRDT[index].DBAU = sgl->List[index].PhysicalAddress.HighPart;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sgl->NumberOfElements;
|
2016-06-20 11:49:22 +00:00
|
|
|
|
}// -- AhciBuild_PRDT();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @name AhciProcessSrb
|
|
|
|
|
* @implemented
|
|
|
|
|
*
|
2016-06-16 17:02:55 +00:00
|
|
|
|
* Prepare Srb for IO processing
|
|
|
|
|
*
|
|
|
|
|
* @param PortExtension
|
|
|
|
|
* @param Srb
|
2016-06-20 11:49:22 +00:00
|
|
|
|
* @param SlotIndex
|
2016-06-16 17:02:55 +00:00
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
AhciProcessSrb (
|
|
|
|
|
__in PAHCI_PORT_EXTENSION PortExtension,
|
2016-06-20 11:49:22 +00:00
|
|
|
|
__in PSCSI_REQUEST_BLOCK Srb,
|
|
|
|
|
__in ULONG SlotIndex
|
2016-06-16 17:02:55 +00:00
|
|
|
|
)
|
|
|
|
|
{
|
2016-06-20 11:49:22 +00:00
|
|
|
|
ULONG prdtlen, sig, length;
|
|
|
|
|
PAHCI_SRB_EXTENSION SrbExtension;
|
|
|
|
|
PAHCI_COMMAND_HEADER CommandHeader;
|
|
|
|
|
PAHCI_ADAPTER_EXTENSION AdapterExtension;
|
|
|
|
|
STOR_PHYSICAL_ADDRESS CommandTablePhysicalAddress;
|
|
|
|
|
|
2016-06-16 17:02:55 +00:00
|
|
|
|
DebugPrint("AhciProcessSrb()\n");
|
|
|
|
|
|
|
|
|
|
NT_ASSERT(Srb->PathId == PortExtension->PortNumber);
|
|
|
|
|
|
2016-06-22 16:08:45 +00:00
|
|
|
|
SrbExtension = GetSrbExtension(Srb);
|
2016-06-20 11:49:22 +00:00
|
|
|
|
AdapterExtension = PortExtension->AdapterExtension;
|
|
|
|
|
|
|
|
|
|
NT_ASSERT(SrbExtension != NULL);
|
|
|
|
|
NT_ASSERT(SrbExtension->AtaFunction != 0);
|
|
|
|
|
|
|
|
|
|
if ((SrbExtension->AtaFunction == ATA_FUNCTION_ATA_IDENTIFY) &&
|
2016-06-22 16:08:45 +00:00
|
|
|
|
(SrbExtension->CommandReg == IDE_COMMAND_NOT_VALID))
|
2016-06-20 11:49:22 +00:00
|
|
|
|
{
|
|
|
|
|
// Here we are safe to check SIG register
|
|
|
|
|
sig = StorPortReadRegisterUlong(AdapterExtension, &PortExtension->Port->SIG);
|
|
|
|
|
if (sig == 0x101)
|
|
|
|
|
{
|
2016-06-22 16:08:45 +00:00
|
|
|
|
SrbExtension->CommandReg = IDE_COMMAND_IDENTIFY;
|
2016-06-20 11:49:22 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-06-22 16:08:45 +00:00
|
|
|
|
SrbExtension->CommandReg = IDE_COMMAND_ATAPI_IDENTIFY;
|
2016-06-20 11:49:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NT_ASSERT(SlotIndex < AHCI_Global_Port_CAP_NCS(AdapterExtension->CAP));
|
|
|
|
|
SrbExtension->SlotIndex = SlotIndex;
|
|
|
|
|
|
|
|
|
|
// program the CFIS in the CommandTable
|
|
|
|
|
CommandHeader = &PortExtension->CommandList[SlotIndex];
|
|
|
|
|
|
|
|
|
|
if (IsAtaCommand(SrbExtension->AtaFunction))
|
|
|
|
|
{
|
|
|
|
|
AhciATA_CFIS(PortExtension, SrbExtension);
|
|
|
|
|
}
|
|
|
|
|
else if (IsAtapiCommand(SrbExtension->AtaFunction))
|
|
|
|
|
{
|
|
|
|
|
AhciATAPI_CFIS(PortExtension, SrbExtension);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prdtlen = 0;
|
|
|
|
|
if (IsDataTransferNeeded(SrbExtension))
|
|
|
|
|
{
|
|
|
|
|
prdtlen = AhciBuild_PRDT(PortExtension, SrbExtension);
|
|
|
|
|
NT_ASSERT(prdtlen != -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Program the command header
|
|
|
|
|
CommandHeader->DI.PRDTL = prdtlen; // number of entries in PRD table
|
|
|
|
|
CommandHeader->DI.CFL = 5;
|
|
|
|
|
CommandHeader->DI.W = (SrbExtension->Flags & ATA_FLAGS_DATA_OUT) ? 1 : 0;
|
|
|
|
|
CommandHeader->DI.P = 0; // ATA Specifications says so
|
|
|
|
|
CommandHeader->DI.PMP = 0; // Port Multiplier
|
|
|
|
|
|
|
|
|
|
// Reset -- Manual Configuation
|
|
|
|
|
CommandHeader->DI.R = 0;
|
|
|
|
|
CommandHeader->DI.B = 0;
|
|
|
|
|
CommandHeader->DI.C = 0;
|
|
|
|
|
|
|
|
|
|
CommandHeader->PRDBC = 0;
|
|
|
|
|
|
|
|
|
|
CommandHeader->Reserved[0] = 0;
|
|
|
|
|
CommandHeader->Reserved[1] = 0;
|
|
|
|
|
CommandHeader->Reserved[2] = 0;
|
|
|
|
|
CommandHeader->Reserved[3] = 0;
|
|
|
|
|
|
|
|
|
|
// set CommandHeader CTBA
|
|
|
|
|
// I am really not sure if SrbExtension is 128 byte aligned or not
|
|
|
|
|
// Command FIS will not work if it is not so.
|
|
|
|
|
CommandTablePhysicalAddress = StorPortGetPhysicalAddress(AdapterExtension,
|
|
|
|
|
NULL,
|
|
|
|
|
SrbExtension,
|
|
|
|
|
&length);
|
|
|
|
|
|
|
|
|
|
// command table alignment
|
|
|
|
|
NT_ASSERT((CommandTablePhysicalAddress.LowPart % 128) == 0);
|
|
|
|
|
|
|
|
|
|
CommandHeader->CTBA0 = CommandTablePhysicalAddress.LowPart;
|
|
|
|
|
|
|
|
|
|
if (IsAdapterCAPS64(AdapterExtension->CAP))
|
|
|
|
|
{
|
|
|
|
|
CommandHeader->CTBA_U0 = CommandTablePhysicalAddress.HighPart;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// mark this slot
|
2016-06-30 16:04:50 +00:00
|
|
|
|
PortExtension->Slot[SlotIndex] = Srb;
|
2016-07-04 19:01:07 +00:00
|
|
|
|
PortExtension->QueueSlots |= 1 << SlotIndex;
|
2016-06-16 17:02:55 +00:00
|
|
|
|
return;
|
|
|
|
|
}// -- AhciProcessSrb();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @name AhciActivatePort
|
2016-06-27 12:58:04 +00:00
|
|
|
|
* @implemented
|
2016-06-16 17:02:55 +00:00
|
|
|
|
*
|
|
|
|
|
* Program Port and populate command list
|
|
|
|
|
*
|
|
|
|
|
* @param PortExtension
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
AhciActivatePort (
|
|
|
|
|
__in PAHCI_PORT_EXTENSION PortExtension
|
|
|
|
|
)
|
|
|
|
|
{
|
2016-07-04 19:01:07 +00:00
|
|
|
|
AHCI_PORT_CMD cmd;
|
|
|
|
|
ULONG QueueSlots, slotToActivate, tmp;
|
2016-06-27 12:58:04 +00:00
|
|
|
|
PAHCI_ADAPTER_EXTENSION AdapterExtension;
|
|
|
|
|
|
2016-06-16 17:02:55 +00:00
|
|
|
|
DebugPrint("AhciActivatePort()\n");
|
|
|
|
|
|
2016-06-27 12:58:04 +00:00
|
|
|
|
AdapterExtension = PortExtension->AdapterExtension;
|
|
|
|
|
QueueSlots = PortExtension->QueueSlots;
|
|
|
|
|
|
|
|
|
|
if (QueueSlots == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// section 3.3.14
|
|
|
|
|
// Bits in this field shall only be set to ‘1’ by software when PxCMD.ST is set to ‘1’
|
2016-07-04 19:01:07 +00:00
|
|
|
|
cmd.Status = StorPortReadRegisterUlong(AdapterExtension, &PortExtension->Port->CMD);
|
2016-06-27 12:58:04 +00:00
|
|
|
|
|
2016-07-04 19:01:07 +00:00
|
|
|
|
if (cmd.ST == 0) // PxCMD.ST == 0
|
2016-06-27 12:58:04 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// get the lowest set bit
|
|
|
|
|
tmp = QueueSlots & (QueueSlots - 1);
|
|
|
|
|
|
|
|
|
|
if (tmp == 0)
|
|
|
|
|
slotToActivate = QueueSlots;
|
|
|
|
|
else
|
|
|
|
|
slotToActivate = (QueueSlots & (~tmp));
|
|
|
|
|
|
|
|
|
|
// mark that bit off in QueueSlots
|
2016-06-30 16:04:50 +00:00
|
|
|
|
// so we can know we it is really needed to activate port or not
|
2016-06-27 12:58:04 +00:00
|
|
|
|
PortExtension->QueueSlots &= ~slotToActivate;
|
|
|
|
|
// mark this CommandIssuedSlots
|
2016-06-30 16:04:50 +00:00
|
|
|
|
// to validate in completeIssuedCommand
|
2016-06-27 12:58:04 +00:00
|
|
|
|
PortExtension->CommandIssuedSlots |= slotToActivate;
|
|
|
|
|
|
|
|
|
|
// tell the HBA to issue this Command Slot to the given port
|
|
|
|
|
StorPortWriteRegisterUlong(AdapterExtension, &PortExtension->Port->CI, slotToActivate);
|
|
|
|
|
|
2016-06-16 17:02:55 +00:00
|
|
|
|
return;
|
|
|
|
|
}// -- AhciActivatePort();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @name AhciProcessIO
|
|
|
|
|
* @implemented
|
|
|
|
|
*
|
|
|
|
|
* Acquire Exclusive lock to port, populate pending commands to command List
|
|
|
|
|
* program controller's port to process new commands in command list.
|
|
|
|
|
*
|
|
|
|
|
* @param AdapterExtension
|
|
|
|
|
* @param PathId
|
|
|
|
|
* @param Srb
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
AhciProcessIO (
|
|
|
|
|
__in PAHCI_ADAPTER_EXTENSION AdapterExtension,
|
|
|
|
|
__in UCHAR PathId,
|
|
|
|
|
__in PSCSI_REQUEST_BLOCK Srb
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
STOR_LOCK_HANDLE lockhandle;
|
|
|
|
|
PSCSI_REQUEST_BLOCK tmpSrb;
|
|
|
|
|
PAHCI_PORT_EXTENSION PortExtension;
|
2016-06-20 11:49:22 +00:00
|
|
|
|
ULONG commandSlotMask, occupiedSlots, slotIndex, NCS;
|
2016-06-16 17:02:55 +00:00
|
|
|
|
|
|
|
|
|
DebugPrint("AhciProcessIO()\n");
|
|
|
|
|
DebugPrint("\tPathId: %d\n", PathId);
|
|
|
|
|
|
|
|
|
|
PortExtension = &AdapterExtension->PortExtension[PathId];
|
|
|
|
|
|
2016-06-16 21:14:03 +00:00
|
|
|
|
NT_ASSERT(PathId < AdapterExtension->PortCount);
|
2016-06-16 17:02:55 +00:00
|
|
|
|
|
|
|
|
|
// add Srb to queue
|
|
|
|
|
AddQueue(&PortExtension->SrbQueue, Srb);
|
|
|
|
|
|
|
|
|
|
if (PortExtension->IsActive == FALSE)
|
|
|
|
|
return; // we should wait for device to get active
|
|
|
|
|
|
|
|
|
|
AhciZeroMemory(&lockhandle, sizeof(lockhandle));
|
|
|
|
|
|
|
|
|
|
// Acquire Lock
|
|
|
|
|
StorPortAcquireSpinLock(AdapterExtension, InterruptLock, NULL, &lockhandle);
|
|
|
|
|
|
2016-06-27 12:58:04 +00:00
|
|
|
|
occupiedSlots = (PortExtension->QueueSlots | PortExtension->CommandIssuedSlots); // Busy command slots for given port
|
2016-06-20 11:49:22 +00:00
|
|
|
|
NCS = AHCI_Global_Port_CAP_NCS(AdapterExtension->CAP);
|
|
|
|
|
commandSlotMask = (1 << NCS) - 1; // available slots mask
|
2016-06-16 17:02:55 +00:00
|
|
|
|
|
|
|
|
|
commandSlotMask = (commandSlotMask & ~occupiedSlots);
|
|
|
|
|
if(commandSlotMask != 0)
|
|
|
|
|
{
|
|
|
|
|
// iterate over HBA port slots
|
2016-06-20 11:49:22 +00:00
|
|
|
|
for (slotIndex = 0; slotIndex < NCS; slotIndex++)
|
2016-06-16 17:02:55 +00:00
|
|
|
|
{
|
|
|
|
|
// find first free slot
|
|
|
|
|
if ((commandSlotMask & (1 << slotIndex)) != 0)
|
|
|
|
|
{
|
|
|
|
|
tmpSrb = RemoveQueue(&PortExtension->SrbQueue);
|
|
|
|
|
if (tmpSrb != NULL)
|
|
|
|
|
{
|
2016-06-22 16:08:45 +00:00
|
|
|
|
NT_ASSERT(tmpSrb->PathId == PathId);
|
2016-06-20 11:49:22 +00:00
|
|
|
|
AhciProcessSrb(PortExtension, tmpSrb, slotIndex);
|
2016-06-16 17:02:55 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// program HBA port
|
|
|
|
|
AhciActivatePort(PortExtension);
|
|
|
|
|
|
|
|
|
|
// Release Lock
|
|
|
|
|
StorPortReleaseSpinLock(AdapterExtension, &lockhandle);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}// -- AhciProcessIO();
|
|
|
|
|
|
2016-06-30 16:04:50 +00:00
|
|
|
|
/**
|
|
|
|
|
* @name InquiryCompletion
|
|
|
|
|
* @not_implemented
|
|
|
|
|
*
|
|
|
|
|
* InquiryCompletion routine should be called after device signals
|
|
|
|
|
* for device inquiry request is completed (through interrupt)
|
|
|
|
|
*
|
|
|
|
|
* @param PortExtension
|
|
|
|
|
* @param Srb
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
InquiryCompletion (
|
|
|
|
|
__in PAHCI_ADAPTER_EXTENSION AdapterExtension,
|
|
|
|
|
__in PAHCI_PORT_EXTENSION PortExtension,
|
|
|
|
|
__in PSCSI_REQUEST_BLOCK Srb
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
ULONG SrbStatus;
|
|
|
|
|
PAHCI_SRB_EXTENSION SrbExtension;
|
|
|
|
|
|
|
|
|
|
DebugPrint("InquiryCompletion()\n");
|
|
|
|
|
|
|
|
|
|
NT_ASSERT(PortExtension != NULL);
|
|
|
|
|
NT_ASSERT(Srb != NULL);
|
|
|
|
|
|
|
|
|
|
SrbStatus = Srb->SrbStatus;
|
|
|
|
|
SrbExtension = GetSrbExtension(Srb);
|
|
|
|
|
|
|
|
|
|
if (SrbStatus == SRB_STATUS_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
if (SrbExtension->CommandReg == IDE_COMMAND_IDENTIFY)
|
|
|
|
|
{
|
2016-07-04 19:01:07 +00:00
|
|
|
|
DebugPrint("Device: ATA\n");
|
2016-06-30 16:04:50 +00:00
|
|
|
|
AdapterExtension->DeviceParams.DeviceType = AHCI_DEVICE_TYPE_ATA;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-07-04 19:01:07 +00:00
|
|
|
|
DebugPrint("Device: ATAPI\n");
|
2016-06-30 16:04:50 +00:00
|
|
|
|
AdapterExtension->DeviceParams.DeviceType = AHCI_DEVICE_TYPE_ATAPI;
|
|
|
|
|
}
|
|
|
|
|
// TODO: Set Device Paramters
|
|
|
|
|
}
|
|
|
|
|
else if (SrbStatus == SRB_STATUS_NO_DEVICE)
|
|
|
|
|
{
|
2016-07-04 19:01:07 +00:00
|
|
|
|
DebugPrint("Device: No Device\n");
|
2016-06-30 16:04:50 +00:00
|
|
|
|
AdapterExtension->DeviceParams.DeviceType = AHCI_DEVICE_TYPE_NODEVICE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}// -- InquiryCompletion();
|
|
|
|
|
|
2016-06-16 17:02:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* @name DeviceInquiryRequest
|
|
|
|
|
* @implemented
|
|
|
|
|
*
|
|
|
|
|
* Tells wheather given port is implemented or not
|
|
|
|
|
*
|
|
|
|
|
* @param AdapterExtension
|
|
|
|
|
* @param Srb
|
|
|
|
|
* @param Cdb
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
* return STOR status for DeviceInquiryRequest
|
|
|
|
|
*
|
|
|
|
|
* @remark
|
|
|
|
|
* http://www.seagate.com/staticfiles/support/disc/manuals/Interface%20manuals/100293068c.pdf
|
|
|
|
|
*/
|
|
|
|
|
ULONG
|
|
|
|
|
DeviceInquiryRequest (
|
|
|
|
|
__in PAHCI_ADAPTER_EXTENSION AdapterExtension,
|
|
|
|
|
__in PSCSI_REQUEST_BLOCK Srb,
|
|
|
|
|
__in PCDB Cdb
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
PVOID DataBuffer;
|
|
|
|
|
ULONG DataBufferLength;
|
2016-06-27 12:58:04 +00:00
|
|
|
|
PAHCI_PORT_EXTENSION PortExtension;
|
2016-06-20 11:49:22 +00:00
|
|
|
|
PAHCI_SRB_EXTENSION SrbExtension;
|
2016-06-16 17:02:55 +00:00
|
|
|
|
|
|
|
|
|
DebugPrint("DeviceInquiryRequest()\n");
|
|
|
|
|
|
2016-06-27 12:58:04 +00:00
|
|
|
|
NT_ASSERT(IsPortValid(AdapterExtension, Srb->PathId));
|
|
|
|
|
|
2016-06-22 16:08:45 +00:00
|
|
|
|
SrbExtension = GetSrbExtension(Srb);
|
2016-06-27 12:58:04 +00:00
|
|
|
|
PortExtension = &AdapterExtension->PortExtension[Srb->PathId];
|
2016-06-20 11:49:22 +00:00
|
|
|
|
|
2016-06-16 17:02:55 +00:00
|
|
|
|
// 3.6.1
|
|
|
|
|
// If the EVPD bit is set to zero, the device server shall return the standard INQUIRY data
|
|
|
|
|
if (Cdb->CDB6INQUIRY3.EnableVitalProductData == 0)
|
|
|
|
|
{
|
|
|
|
|
DebugPrint("\tEVPD Inquired\n");
|
2016-06-20 11:49:22 +00:00
|
|
|
|
NT_ASSERT(SrbExtension != NULL);
|
|
|
|
|
|
|
|
|
|
SrbExtension->AtaFunction = ATA_FUNCTION_ATA_IDENTIFY;
|
2016-06-27 12:58:04 +00:00
|
|
|
|
SrbExtension->Flags |= ATA_FLAGS_DATA_IN;
|
2016-06-30 16:04:50 +00:00
|
|
|
|
SrbExtension->CompletionRoutine = InquiryCompletion;
|
2016-06-22 16:08:45 +00:00
|
|
|
|
SrbExtension->CommandReg = IDE_COMMAND_NOT_VALID;
|
2016-06-27 12:58:04 +00:00
|
|
|
|
|
2016-06-30 16:04:50 +00:00
|
|
|
|
// TODO: Should use AhciZeroMemory
|
2016-06-27 12:58:04 +00:00
|
|
|
|
SrbExtension->FeaturesLow = 0;
|
|
|
|
|
SrbExtension->LBA0 = 0;
|
|
|
|
|
SrbExtension->LBA1 = 0;
|
|
|
|
|
SrbExtension->LBA2 = 0;
|
|
|
|
|
SrbExtension->Device = 0;
|
|
|
|
|
SrbExtension->LBA3 = 0;
|
|
|
|
|
SrbExtension->LBA4 = 0;
|
|
|
|
|
SrbExtension->LBA5 = 0;
|
|
|
|
|
SrbExtension->FeaturesHigh = 0;
|
|
|
|
|
SrbExtension->SectorCountLow = 0;
|
|
|
|
|
SrbExtension->SectorCountHigh = 0;
|
|
|
|
|
|
|
|
|
|
SrbExtension->Sgl.NumberOfElements = 1;
|
|
|
|
|
SrbExtension->Sgl.List[0].PhysicalAddress.LowPart = PortExtension->IdentifyDeviceDataPhysicalAddress.LowPart;
|
|
|
|
|
SrbExtension->Sgl.List[0].PhysicalAddress.HighPart = PortExtension->IdentifyDeviceDataPhysicalAddress.HighPart;
|
|
|
|
|
SrbExtension->Sgl.List[0].Length = sizeof(IDENTIFY_DEVICE_DATA);
|
2016-06-16 17:02:55 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DebugPrint("\tVPD Inquired\n");
|
|
|
|
|
|
|
|
|
|
DataBuffer = Srb->DataBuffer;
|
|
|
|
|
DataBufferLength = Srb->DataTransferLength;
|
|
|
|
|
|
|
|
|
|
if (DataBuffer == NULL)
|
|
|
|
|
{
|
|
|
|
|
return SRB_STATUS_INVALID_REQUEST;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AhciZeroMemory(DataBuffer, DataBufferLength);
|
2016-06-27 12:58:04 +00:00
|
|
|
|
|
|
|
|
|
// not supported
|
|
|
|
|
return SRB_STATUS_BAD_FUNCTION;
|
2016-06-16 17:02:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AhciProcessIO(AdapterExtension, Srb->PathId, Srb);
|
2016-06-27 12:58:04 +00:00
|
|
|
|
return SRB_STATUS_PENDING;
|
2016-06-16 17:02:55 +00:00
|
|
|
|
}// -- DeviceInquiryRequest();
|
|
|
|
|
|
2016-06-02 14:43:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* @name AhciAdapterReset
|
|
|
|
|
* @implemented
|
|
|
|
|
*
|
|
|
|
|
* 10.4.3 HBA Reset
|
|
|
|
|
* If the HBA becomes unusable for multiple ports, and a software reset or port reset does not correct the
|
|
|
|
|
* problem, software may reset the entire HBA by setting GHC.HR to ‘1’. When software sets the GHC.HR
|
|
|
|
|
* bit to ‘1’, the HBA shall perform an internal reset action. The bit shall be cleared to ‘0’ by the HBA when
|
|
|
|
|
* the reset is complete. A software write of ‘0’ to GHC.HR shall have no effect. To perform the HBA reset,
|
|
|
|
|
* software sets GHC.HR to ‘1’ and may poll until this bit is read to be ‘0’, at which point software knows that
|
|
|
|
|
* the HBA reset has completed.
|
|
|
|
|
* If the HBA has not cleared GHC.HR to ‘0’ within 1 second of software setting GHC.HR to ‘1’, the HBA is in
|
2016-06-07 11:05:32 +00:00
|
|
|
|
* a hung or locked state.
|
2016-06-02 14:43:56 +00:00
|
|
|
|
*
|
2016-06-10 08:27:20 +00:00
|
|
|
|
* @param AdapterExtension
|
2016-06-02 14:43:56 +00:00
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
* TRUE in case AHCI Controller RESTARTED successfully. i.e GHC.HR == 0
|
|
|
|
|
*/
|
2016-06-09 23:47:19 +00:00
|
|
|
|
BOOLEAN
|
|
|
|
|
AhciAdapterReset (
|
2016-06-10 08:27:20 +00:00
|
|
|
|
__in PAHCI_ADAPTER_EXTENSION AdapterExtension
|
2016-06-09 23:47:19 +00:00
|
|
|
|
)
|
2016-06-02 14:13:06 +00:00
|
|
|
|
{
|
2016-06-10 08:27:20 +00:00
|
|
|
|
ULONG ghc, ticks, ghcStatus;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
PAHCI_MEMORY_REGISTERS abar = NULL;
|
2016-06-02 14:43:56 +00:00
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
DebugPrint("AhciAdapterReset()\n");
|
2016-06-02 14:43:56 +00:00
|
|
|
|
|
2016-06-10 08:27:20 +00:00
|
|
|
|
abar = AdapterExtension->ABAR_Address;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
if (abar == NULL) // basic sanity
|
2016-06-09 23:47:19 +00:00
|
|
|
|
{
|
2016-06-02 14:43:56 +00:00
|
|
|
|
return FALSE;
|
2016-06-09 23:47:19 +00:00
|
|
|
|
}
|
2016-06-02 14:43:56 +00:00
|
|
|
|
|
2016-06-04 12:52:38 +00:00
|
|
|
|
// HR -- Very first bit (lowest significant)
|
2016-06-07 18:06:51 +00:00
|
|
|
|
ghc = AHCI_Global_HBA_CONTROL_HR;
|
2016-06-10 08:27:20 +00:00
|
|
|
|
StorPortWriteRegisterUlong(AdapterExtension, &abar->GHC, ghc);
|
2016-06-02 14:43:56 +00:00
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
for (ticks = 0; ticks < 50; ++ticks)
|
|
|
|
|
{
|
2016-06-10 08:27:20 +00:00
|
|
|
|
ghcStatus = StorPortReadRegisterUlong(AdapterExtension, &abar->GHC);
|
|
|
|
|
if ((ghcStatus & AHCI_Global_HBA_CONTROL_HR) == 0)
|
2016-06-09 23:47:19 +00:00
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
StorPortStallExecution(20000);
|
|
|
|
|
}
|
2016-06-02 14:43:56 +00:00
|
|
|
|
|
2016-06-09 23:47:19 +00:00
|
|
|
|
if (ticks == 50)// 1 second
|
|
|
|
|
{
|
|
|
|
|
DebugPrint("\tDevice Timeout\n");
|
2016-06-02 14:43:56 +00:00
|
|
|
|
return FALSE;
|
2016-06-04 12:52:38 +00:00
|
|
|
|
}
|
2016-06-02 14:43:56 +00:00
|
|
|
|
|
2016-06-04 12:52:38 +00:00
|
|
|
|
return TRUE;
|
2016-06-02 14:13:06 +00:00
|
|
|
|
}// -- AhciAdapterReset();
|
2016-06-03 15:54:21 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @name AhciZeroMemory
|
|
|
|
|
* @implemented
|
|
|
|
|
*
|
|
|
|
|
* Clear buffer by filling zeros
|
|
|
|
|
*
|
2016-06-10 08:27:20 +00:00
|
|
|
|
* @param Buffer
|
|
|
|
|
* @param BufferSize
|
2016-06-03 15:54:21 +00:00
|
|
|
|
*/
|
2016-06-07 11:05:32 +00:00
|
|
|
|
__inline
|
2016-06-09 23:47:19 +00:00
|
|
|
|
VOID
|
|
|
|
|
AhciZeroMemory (
|
2016-06-10 08:27:20 +00:00
|
|
|
|
__out PCHAR Buffer,
|
|
|
|
|
__in ULONG BufferSize
|
2016-06-09 23:47:19 +00:00
|
|
|
|
)
|
2016-06-03 15:54:21 +00:00
|
|
|
|
{
|
|
|
|
|
ULONG i;
|
2016-06-10 08:27:20 +00:00
|
|
|
|
for (i = 0; i < BufferSize; i++)
|
|
|
|
|
{
|
|
|
|
|
Buffer[i] = 0;
|
|
|
|
|
}
|
2016-06-16 17:02:55 +00:00
|
|
|
|
|
|
|
|
|
return;
|
2016-06-03 15:54:21 +00:00
|
|
|
|
}// -- AhciZeroMemory();
|
2016-06-07 11:05:32 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @name IsPortValid
|
|
|
|
|
* @implemented
|
|
|
|
|
*
|
|
|
|
|
* Tells wheather given port is implemented or not
|
|
|
|
|
*
|
2016-06-10 08:27:20 +00:00
|
|
|
|
* @param AdapterExtension
|
2016-06-07 11:05:32 +00:00
|
|
|
|
* @param PathId
|
|
|
|
|
*
|
|
|
|
|
* @return
|
2016-06-07 18:06:51 +00:00
|
|
|
|
* return TRUE if provided port is valid (implemented) or not
|
2016-06-07 11:05:32 +00:00
|
|
|
|
*/
|
|
|
|
|
__inline
|
2016-06-09 23:47:19 +00:00
|
|
|
|
BOOLEAN
|
|
|
|
|
IsPortValid (
|
2016-06-10 08:27:20 +00:00
|
|
|
|
__in PAHCI_ADAPTER_EXTENSION AdapterExtension,
|
|
|
|
|
__in UCHAR pathId
|
2016-06-09 23:47:19 +00:00
|
|
|
|
)
|
2016-06-07 11:05:32 +00:00
|
|
|
|
{
|
2016-06-09 23:47:19 +00:00
|
|
|
|
NT_ASSERT(pathId >= 0);
|
|
|
|
|
|
2016-06-16 21:14:03 +00:00
|
|
|
|
if (pathId >= AdapterExtension->PortCount)
|
2016-06-09 23:47:19 +00:00
|
|
|
|
{
|
2016-06-07 11:05:32 +00:00
|
|
|
|
return FALSE;
|
2016-06-09 23:47:19 +00:00
|
|
|
|
}
|
2016-06-07 18:06:51 +00:00
|
|
|
|
|
2016-06-10 08:27:20 +00:00
|
|
|
|
return AdapterExtension->PortExtension[pathId].IsActive;
|
2016-06-07 11:05:32 +00:00
|
|
|
|
}// -- IsPortValid()
|
2016-06-07 18:06:51 +00:00
|
|
|
|
|
2016-06-15 17:07:26 +00:00
|
|
|
|
/**
|
2016-06-16 17:02:55 +00:00
|
|
|
|
* @name AddQueue
|
|
|
|
|
* @implemented
|
2016-06-15 17:07:26 +00:00
|
|
|
|
*
|
2016-06-16 17:02:55 +00:00
|
|
|
|
* Add Srb to Queue
|
2016-06-15 17:07:26 +00:00
|
|
|
|
*
|
2016-06-16 17:02:55 +00:00
|
|
|
|
* @param Queue
|
2016-06-15 17:07:26 +00:00
|
|
|
|
* @param Srb
|
|
|
|
|
*
|
2016-06-16 17:02:55 +00:00
|
|
|
|
* @return
|
|
|
|
|
* return TRUE if Srb is successfully added to Queue
|
|
|
|
|
*
|
2016-06-15 17:07:26 +00:00
|
|
|
|
*/
|
2016-06-16 17:02:55 +00:00
|
|
|
|
__inline
|
|
|
|
|
BOOLEAN
|
|
|
|
|
AddQueue (
|
|
|
|
|
__inout PAHCI_QUEUE Queue,
|
|
|
|
|
__in PVOID Srb
|
2016-06-15 17:07:26 +00:00
|
|
|
|
)
|
|
|
|
|
{
|
2016-06-16 17:02:55 +00:00
|
|
|
|
NT_ASSERT(Queue->Head < MAXIMUM_QUEUE_BUFFER_SIZE);
|
|
|
|
|
NT_ASSERT(Queue->Tail < MAXIMUM_QUEUE_BUFFER_SIZE);
|
2016-06-15 17:07:26 +00:00
|
|
|
|
|
2016-06-22 16:08:45 +00:00
|
|
|
|
if (Queue->Tail == ((Queue->Head + 1) % MAXIMUM_QUEUE_BUFFER_SIZE))
|
2016-06-16 17:02:55 +00:00
|
|
|
|
return FALSE;
|
2016-06-15 17:07:26 +00:00
|
|
|
|
|
2016-06-16 17:02:55 +00:00
|
|
|
|
Queue->Buffer[Queue->Head++] = Srb;
|
|
|
|
|
Queue->Head %= MAXIMUM_QUEUE_BUFFER_SIZE;
|
2016-06-15 17:07:26 +00:00
|
|
|
|
|
2016-06-16 17:02:55 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}// -- AddQueue();
|
2016-06-15 17:07:26 +00:00
|
|
|
|
|
2016-06-07 18:06:51 +00:00
|
|
|
|
/**
|
2016-06-16 17:02:55 +00:00
|
|
|
|
* @name RemoveQueue
|
2016-06-07 18:06:51 +00:00
|
|
|
|
* @implemented
|
|
|
|
|
*
|
2016-06-16 17:02:55 +00:00
|
|
|
|
* Remove and return Srb from Queue
|
2016-06-07 18:06:51 +00:00
|
|
|
|
*
|
2016-06-16 17:02:55 +00:00
|
|
|
|
* @param Queue
|
2016-06-07 18:06:51 +00:00
|
|
|
|
*
|
|
|
|
|
* @return
|
2016-06-16 17:02:55 +00:00
|
|
|
|
* return Srb
|
2016-06-07 18:06:51 +00:00
|
|
|
|
*
|
|
|
|
|
*/
|
2016-06-16 17:02:55 +00:00
|
|
|
|
__inline
|
|
|
|
|
PVOID
|
|
|
|
|
RemoveQueue (
|
|
|
|
|
__inout PAHCI_QUEUE Queue
|
2016-06-09 23:47:19 +00:00
|
|
|
|
)
|
2016-06-07 18:06:51 +00:00
|
|
|
|
{
|
2016-06-16 17:02:55 +00:00
|
|
|
|
PVOID Srb;
|
2016-06-07 18:06:51 +00:00
|
|
|
|
|
2016-06-16 17:02:55 +00:00
|
|
|
|
NT_ASSERT(Queue->Head < MAXIMUM_QUEUE_BUFFER_SIZE);
|
|
|
|
|
NT_ASSERT(Queue->Tail < MAXIMUM_QUEUE_BUFFER_SIZE);
|
2016-06-07 18:06:51 +00:00
|
|
|
|
|
2016-06-16 17:02:55 +00:00
|
|
|
|
if (Queue->Head == Queue->Tail)
|
|
|
|
|
return NULL;
|
2016-06-07 18:06:51 +00:00
|
|
|
|
|
2016-06-16 17:02:55 +00:00
|
|
|
|
Srb = Queue->Buffer[Queue->Tail++];
|
|
|
|
|
Queue->Tail %= MAXIMUM_QUEUE_BUFFER_SIZE;
|
2016-06-07 18:06:51 +00:00
|
|
|
|
|
2016-06-16 17:02:55 +00:00
|
|
|
|
return Srb;
|
|
|
|
|
}// -- RemoveQueue();
|
2016-06-22 16:08:45 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @name GetSrbExtension
|
|
|
|
|
* @implemented
|
|
|
|
|
*
|
|
|
|
|
* GetSrbExtension from Srb make sure It is properly aligned
|
|
|
|
|
*
|
|
|
|
|
* @param Srb
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
* return SrbExtension
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
__inline
|
|
|
|
|
PAHCI_SRB_EXTENSION
|
|
|
|
|
GetSrbExtension (
|
|
|
|
|
__in PSCSI_REQUEST_BLOCK Srb
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
ULONG Offset;
|
|
|
|
|
ULONG_PTR SrbExtension;
|
|
|
|
|
|
|
|
|
|
SrbExtension = Srb->SrbExtension;
|
|
|
|
|
Offset = SrbExtension % 128;
|
|
|
|
|
|
|
|
|
|
// CommandTable should be 128 byte aligned
|
|
|
|
|
if (Offset != 0)
|
|
|
|
|
Offset = 128 - Offset;
|
|
|
|
|
|
|
|
|
|
return (PAHCI_SRB_EXTENSION)(SrbExtension + Offset);
|
|
|
|
|
}// -- PAHCI_SRB_EXTENSION();
|