forked from winfsp/winspd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadapter.c
154 lines (131 loc) · 4.46 KB
/
adapter.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**
* @file sys/adapter.c
*
* @copyright 2018-2019 Bill Zissimopoulos
*/
/*
* This file is part of WinSpd.
*
* You can redistribute it and/or modify it under the terms of the GNU
* General Public License version 3 as published by the Free Software
* Foundation.
*
* Licensees holding a valid commercial license may use this software
* in accordance with the commercial license agreement provided in
* conjunction with the software. The terms and conditions of any such
* commercial license agreement shall govern, supersede, and render
* ineffective any application of the GPLv3 license to this software,
* notwithstanding of any reference thereto in the software or
* associated repository.
*/
#include <sys/driver.h>
ULONG SpdHwFindAdapter(
PVOID DeviceExtension0,
PVOID HwContext,
PVOID BusInformation,
PVOID LowerDevice,
PCHAR ArgumentString,
PPORT_CONFIGURATION_INFORMATION ConfigInfo,
PBOOLEAN Again)
{
ULONG Result = SP_RETURN_NOT_FOUND;
SPD_ENTER(adapter,
ASSERT(PASSIVE_LEVEL == KeGetCurrentIrql()));
SPD_DEVICE_EXTENSION *DeviceExtension = DeviceExtension0;
if (NT_SUCCESS(SpdDeviceExtensionInit(DeviceExtension, BusInformation)))
{
ConfigInfo->MaximumTransferLength = SP_UNINITIALIZED_VALUE;
ConfigInfo->NumberOfPhysicalBreaks = SP_UNINITIALIZED_VALUE;
ConfigInfo->AlignmentMask = FILE_BYTE_ALIGNMENT;
ConfigInfo->NumberOfBuses = 1;
ConfigInfo->ScatterGather = TRUE;
ConfigInfo->Master = TRUE;
ConfigInfo->CachesData = TRUE;
ConfigInfo->MaximumNumberOfTargets = (UCHAR)DeviceExtension->StorageUnitCapacity;
ConfigInfo->MaximumNumberOfLogicalUnits = 1;
ConfigInfo->WmiDataProvider = FALSE;
ConfigInfo->SynchronizationModel = StorSynchronizeFullDuplex;
ConfigInfo->VirtualDevice = TRUE;
Result = SP_RETURN_FOUND;
}
SPD_LEAVE(adapter,
"%p, HwContext=%p, BusInformation=%p, LowerDevice=%p, ArgumentString=\"%s\"",
" = %lu",
DeviceExtension0, HwContext, BusInformation, LowerDevice, ArgumentString, Result);
return Result;
}
BOOLEAN SpdHwInitialize(PVOID DeviceExtension)
{
BOOLEAN Result = TRUE;
SPD_ENTER(adapter);
SPD_LEAVE(adapter,
"%p", " = %d",
DeviceExtension, Result);
return Result;
}
VOID SpdHwFreeAdapterResources(PVOID DeviceExtension)
{
SPD_ENTER(adapter,
ASSERT(PASSIVE_LEVEL == KeGetCurrentIrql()));
SpdDeviceExtensionFini(DeviceExtension);
SPD_LEAVE(adapter,
"%p", "",
DeviceExtension);
}
BOOLEAN SpdHwResetBus(PVOID DeviceExtension0, ULONG PathId)
{
BOOLEAN Result = FALSE;
SPD_ENTER(adapter);
if (0 == PathId)
{
SPD_DEVICE_EXTENSION *DeviceExtension = DeviceExtension0;
SPD_STORAGE_UNIT *StorageUnit;
for (ULONG I = 0; DeviceExtension->StorageUnitCapacity > I; I++)
{
StorageUnit = SpdStorageUnitReferenceByBtl(DeviceExtension, SPD_IOCTL_BTL(0, I, 0));
if (0 == StorageUnit)
continue;
SpdIoqReset(StorageUnit->Ioq, FALSE);
SpdStorageUnitDereference(DeviceExtension, StorageUnit);
}
Result = TRUE;
}
SPD_LEAVE(adapter,
"%p, PathId=%lu", " = %d",
DeviceExtension0, PathId, Result);
return Result;
}
SCSI_ADAPTER_CONTROL_STATUS SpdHwAdapterControl(
PVOID DeviceExtension,
SCSI_ADAPTER_CONTROL_TYPE ControlType,
PVOID Parameters)
{
SCSI_ADAPTER_CONTROL_STATUS Result = ScsiAdapterControlUnsuccessful;
SPD_ENTER(adapter);
switch (ControlType)
{
case ScsiQuerySupportedControlTypes:
#define SetSupportedControlType(i) \
if (((PSCSI_SUPPORTED_CONTROL_TYPE_LIST)Parameters)->MaxControlType > (i))\
((PSCSI_SUPPORTED_CONTROL_TYPE_LIST)Parameters)->SupportedTypeList[(i)] = TRUE
SetSupportedControlType(ScsiQuerySupportedControlTypes);
SetSupportedControlType(ScsiStopAdapter);
SetSupportedControlType(ScsiRestartAdapter);
Result = ScsiAdapterControlSuccess;
break;
#undef SetSupportedControlType
case ScsiStopAdapter:
Result = ScsiAdapterControlSuccess;
break;
case ScsiRestartAdapter:
Result = ScsiAdapterControlSuccess;
break;
default:
Result = ScsiAdapterControlUnsuccessful;
break;
}
SPD_LEAVE(adapter,
"%p, ControlType=%s", " = %d",
DeviceExtension, AdapterControlSym(ControlType), (int)Result);
return Result;
}