forked from filipnavara/igb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink.cpp
More file actions
93 lines (75 loc) · 2.39 KB
/
link.cpp
File metadata and controls
93 lines (75 loc) · 2.39 KB
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
#include "precomp.h"
#include "trace.h"
#include "adapter.h"
#include "device.h"
#include "link.h"
#include "interrupt.h"
#define MBit 1000000ULL
void IgbResetLink(_In_ IGB_ADAPTER* adapter)
{
DBGPRINT("IntelResetLink\n");
// Clear bad data from Rx FIFOs
e1000_rx_fifo_flush_base(&adapter->Hw);
e1000_clear_hw_cntrs_base_generic(&adapter->Hw);
adapter->Hw.mac.get_link_status = 1;
WdfInterruptAcquireLock(adapter->MiscInterrupt->Handle);
// Clears any pending interrupts
E1000_READ_REG(&adapter->Hw, E1000_ICR);
E1000_READ_REG(&adapter->Hw, E1000_EICR);
// Enable link interrupts
E1000_WRITE_REG(&adapter->Hw, E1000_IMS, E1000_IMS_LSC);
E1000_WRITE_FLUSH(&adapter->Hw);
E1000_WRITE_REG(&adapter->Hw, E1000_VET, /*ETHERTYPE_VLAN*/0x8100);
e1000_get_phy_info(&adapter->Hw);
WdfInterruptReleaseLock(adapter->MiscInterrupt->Handle);
IgbCheckLinkStatus(adapter);
}
void IgbCheckLinkStatus(_In_ IGB_ADAPTER* adapter)
{
DBGPRINT("IntelCheckLinkStatus\n");
struct e1000_hw* hw = &adapter->Hw;
bool link_up;
e1000_check_for_link(hw);
link_up = !hw->mac.get_link_status;
if (link_up)
{
u16 link_speed;
u16 link_duplex;
e1000_get_speed_and_duplex(hw, &link_speed, &link_duplex);
DBGPRINT("UP speed: %d duplex: %d\n", link_speed, link_duplex);
NET_ADAPTER_PAUSE_FUNCTION_TYPE pauseFunction = NetAdapterPauseFunctionTypeUnknown;
switch (hw->fc.current_mode)
{
case e1000_fc_none:
pauseFunction = NetAdapterPauseFunctionTypeUnsupported;
break;
case e1000_fc_rx_pause:
pauseFunction = NetAdapterPauseFunctionTypeReceiveOnly;
break;
case e1000_fc_tx_pause:
pauseFunction = NetAdapterPauseFunctionTypeSendOnly;
break;
case e1000_fc_full:
pauseFunction = NetAdapterPauseFunctionTypeSendAndReceive;
break;
}
NET_ADAPTER_LINK_STATE linkState;
NET_ADAPTER_LINK_STATE_INIT(
&linkState,
link_speed * MBit,
MediaConnectStateConnected,
link_duplex == FULL_DUPLEX ? MediaDuplexStateFull : MediaDuplexStateHalf,
pauseFunction,
NetAdapterAutoNegotiationFlagXmitLinkSpeedAutoNegotiated |
NetAdapterAutoNegotiationFlagRcvLinkSpeedautoNegotiated |
NetAdapterAutoNegotiationFlagDuplexAutoNegotiated);
NetAdapterSetLinkState(adapter->NetAdapter, &linkState);
}
else
{
DBGPRINT("DOWN\n");
NET_ADAPTER_LINK_STATE linkState;
NET_ADAPTER_LINK_STATE_INIT_DISCONNECTED(&linkState);
NetAdapterSetLinkState(adapter->NetAdapter, &linkState);
}
}