ReactOS 0.4.15-dev-7674-gc0b4db1
media040.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS DC21x4 Driver
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: 21040 media support code
5 * COPYRIGHT: Copyright 2023 Dmitry Borisov <di.sean@protonmail.com>
6 */
7
8/* INCLUDES *******************************************************************/
9
10#include "dc21x4.h"
11
12#include <debug.h>
13
14/* FUNCTIONS ******************************************************************/
15
16VOID
18 _In_ PDC21X4_ADAPTER Adapter,
19 _In_ ULONG InterruptStatus)
20{
21 UNREFERENCED_PARAMETER(InterruptStatus);
22
23 INFO_VERB("Link failed, CSR12 %08lx\n", DC_READ(Adapter, DcCsr12_SiaStatus));
24
25 NdisDprAcquireSpinLock(&Adapter->ModeLock);
26
27 /* Start the media timer when the 10Base-T link has changed state */
28 if (Adapter->MediaNumber != MEDIA_BNC)
29 {
31
32 NdisMSetTimer(&Adapter->MediaMonitorTimer, 3000);
33 }
34
35 NdisDprReleaseSpinLock(&Adapter->ModeLock);
36}
37
38VOID
41 _In_ PVOID SystemSpecific1,
45{
47 BOOLEAN LinkUp, Report, RunAgain;
48
49 UNREFERENCED_PARAMETER(SystemSpecific1);
52
53 if (!(Adapter->Flags & DC_ACTIVE))
54 return;
55
56 LinkUp = FALSE;
57 Report = FALSE;
58 RunAgain = TRUE;
59
61
62 if (Adapter->MediaNumber != MEDIA_BNC)
63 {
64 ULONG SiaStatus = DC_READ(Adapter, DcCsr12_SiaStatus);
65
66 Report = TRUE;
69
70 if (!LinkUp)
71 {
72 /* Select the other port */
73 if (!MEDIA_IS_FIXED(Adapter))
74 {
75 Adapter->MediaNumber = MEDIA_BNC;
76
77 DcWriteSia(Adapter,
78 Adapter->Media[MEDIA_BNC].Csr13,
79 Adapter->Media[MEDIA_BNC].Csr14,
80 Adapter->Media[MEDIA_BNC].Csr15);
81
82 Adapter->LastReceiveActivity = (ULONG)Adapter->Statistics.ReceiveOk;
83 }
84 }
85 else
86 {
87 /* Wait until the next link change event */
88 RunAgain = FALSE;
89 }
90 }
91 else
92 {
94
95 if (!(Adapter->ModeFlags & DC_MODE_TEST_PACKET))
96 {
97 /* Check for any received packets */
99 {
100 LinkUp = TRUE;
101 Report = TRUE;
102 }
103 else
104 {
105 /* Send a loopback packet */
107 DcTestPacket(Adapter);
109 }
110 }
111 else
112 {
113 Adapter->ModeFlags &= ~DC_MODE_TEST_PACKET;
114
115 LinkUp = !!Adapter->MediaTestStatus;
116 Report = TRUE;
117
118 /* Select the other port */
119 if (!LinkUp && !MEDIA_IS_FIXED(Adapter))
120 {
121 Adapter->MediaNumber = MEDIA_10T;
122
123 DcWriteSia(Adapter,
124 Adapter->Media[MEDIA_10T].Csr13,
125 Adapter->Media[MEDIA_10T].Csr14,
126 Adapter->Media[MEDIA_10T].Csr15);
127 }
128 }
130 }
131
132 if (Report)
133 {
135 }
136
138
139 if (RunAgain)
140 {
141 NdisMSetTimer(&Adapter->MediaMonitorTimer, LinkUp ? 6000 : 3000);
142 }
143}
unsigned char BOOLEAN
#define DC_ACTIVE
Definition: dc21x4.h:120
FORCEINLINE ULONG DC_READ(_In_ PDC21X4_ADAPTER Adapter, _In_ DC_CSR Register)
Definition: dc21x4.h:262
NDIS_TIMER_FUNCTION MediaMonitor21040Dpc
Definition: dc21x4.h:497
VOID MediaIndicateConnect(_In_ PDC21X4_ADAPTER Adapter, _In_ BOOLEAN LinkUp)
Definition: media.c:17
MEDIA_HANDLE_LINK_STATE_CHANGE MediaLinkStateChange21040
Definition: dc21x4.h:502
VOID DcWriteSia(_In_ PDC21X4_ADAPTER Adapter, _In_ ULONG Csr13, _In_ ULONG Csr14, _In_ ULONG Csr15)
Definition: hardware.c:89
#define DC_MODE_TEST_PACKET
Definition: dc21x4.h:165
VOID DcTestPacket(_In_ PDC21X4_ADAPTER Adapter)
Definition: hardware.c:135
@ DcCsr12_SiaStatus
Definition: dc21x4hw.h:188
#define DC_SIA_STATUS_10T_LINK_FAIL
Definition: dc21x4hw.h:422
#define DC_SIA_STATUS_NETWORK_CONNECTION_ERROR
Definition: dc21x4hw.h:420
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define INFO_VERB
Definition: debug.h:90
VOID EXPORT NdisMSetTimer(IN PNDIS_MINIPORT_TIMER Timer, IN UINT MillisecondsToDelay)
Definition: time.c:272
if(dx< 0)
Definition: linetemp.h:194
#define MEDIA_IS_FIXED(Adapter)
Definition: media.h:126
#define MEDIA_10T
Definition: media.h:46
#define MEDIA_BNC
Definition: media.h:47
#define _In_
Definition: ms_sal.h:308
_In_ PVOID _In_ PVOID SystemSpecific2
Definition: ndis.h:638
#define NdisDprReleaseSpinLock(_SpinLock)
Definition: ndis.h:4133
_In_ PVOID FunctionContext
Definition: ndis.h:637
#define NdisDprAcquireSpinLock(_SpinLock)
Definition: ndis.h:4124
_In_ PVOID _In_ PVOID _In_ PVOID SystemSpecific3
Definition: ndis.h:639
static NTSTATUS ReceiveActivity(PAFD_FCB FCB, PIRP Irp)
Definition: read.c:151
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
@ LinkUp
Definition: srb.h:741
volatile LONG MediaTestStatus
Definition: dc21x4.h:180
ULONG ModeFlags
Definition: dc21x4.h:162
DECLSPEC_CACHEALIGN NDIS_SPIN_LOCK ModeLock
Definition: dc21x4.h:161
ULONG LastReceiveActivity
Definition: dc21x4.h:179
ULONG MediaNumber
Definition: dc21x4.h:174
NDIS_MINIPORT_TIMER MediaMonitorTimer
Definition: dc21x4.h:181
DC_MEDIA Media[MEDIA_LIST_MAX]
Definition: dc21x4.h:183
DECLSPEC_CACHEALIGN NDIS_SPIN_LOCK SendLock
Definition: dc21x4.h:129
DC_STATISTICS Statistics
Definition: dc21x4.h:156
ULONG Flags
Definition: dc21x4.h:119
ULONG Csr14
Definition: media.h:22
ULONG Csr13
Definition: media.h:21
ULONG Csr15
Definition: media.h:23
ULONG64 ReceiveOk
Definition: dc21x4.h:90
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG
Definition: typedefs.h:59