forked from coolstar/if_re-win
-
Notifications
You must be signed in to change notification settings - Fork 0
/
power.cpp
80 lines (64 loc) · 1.78 KB
/
power.cpp
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
#include "precomp.h"
#include "trace.h"
#include "power.h"
#include "device.h"
#include "adapter.h"
#include "link.h"
_Use_decl_annotations_
NTSTATUS
EvtDeviceD0Entry(
_In_ WDFDEVICE wdfDevice,
WDF_POWER_DEVICE_STATE previousState)
{
RT_ADAPTER* adapter = RtGetDeviceContext(wdfDevice)->Adapter;
TraceEntryRtAdapter(
adapter,
TraceLoggingUInt32(previousState, "PreviousState"));
if (previousState != WdfPowerDeviceD3Final)
{
// We're coming back from low power, undo what
// we did in EvtDeviceD0Exit
re_softc* sc = &adapter->bsdData;
sc->prohibit_access_reg = 0;
re_exit_oob(sc);
re_hw_init(sc);
re_reset(sc);
re_phy_power_up(sc);
re_hw_phy_config(sc);
RtlFirstStart(adapter);
}
TraceExitResult(STATUS_SUCCESS);
return STATUS_SUCCESS;
}
_Use_decl_annotations_
NTSTATUS
EvtDeviceD0Exit(
_In_ WDFDEVICE Device,
_In_ WDF_POWER_DEVICE_STATE TargetState
)
{
RT_ADAPTER* adapter = RtGetDeviceContext(Device)->Adapter;
TraceEntry();
re_softc* sc = &adapter->bsdData;
if (TargetState != WdfPowerDeviceD3Final)
{
re_stop(sc);
re_hw_d3_para(sc);
sc->prohibit_access_reg = 1;
NET_ADAPTER_LINK_STATE linkState;
NET_ADAPTER_LINK_STATE_INIT(
&linkState,
NDIS_LINK_SPEED_UNKNOWN,
MediaConnectStateUnknown,
MediaDuplexStateUnknown,
NetAdapterPauseFunctionTypeUnknown,
NetAdapterAutoNegotiationFlagNone);
NetAdapterSetLinkState(adapter->NetAdapter, &linkState);
}
else {
// Reset MAC address
re_rar_set(sc, adapter->PermanentAddress.Address);
}
TraceExitResult(STATUS_SUCCESS);
return STATUS_SUCCESS;
}