ReactOS 0.4.15-dev-8145-ga541a46
media140.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: 21140 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
16static
19 _In_ PDC21X4_ADAPTER Adapter)
20{
21 ULONG GpioData;
22 PDC_MEDIA Media;
23
24 Media = &Adapter->Media[Adapter->MediaNumber];
25
26 /* No media activity indicator */
27 if (Media->LinkMask == 0)
28 {
29 TRACE("No activity indicator\n");
30
31 /* Assume we have a link */
32 if (MEDIA_IS_FIXED(Adapter))
33 return TRUE;
34
35 return FALSE;
36 }
37
38 GpioData = DC_READ(Adapter, DcCsr12_Gpio);
39
40 TRACE("CSR12 %08lx\n", GpioData);
41
42 /* This media supports link indication via GPIO pins */
43 return !!((GpioData & Media->LinkMask) ^ Media->Polarity);
44}
45
46static
49 _In_ PDC21X4_ADAPTER Adapter)
50{
51 ULONG i;
52
53 /* No half-duplex media in the media list */
54 if (!(Adapter->MediaBitmap & ~MEDIA_FD_MASK))
55 {
56 return Adapter->MediaNumber;
57 }
58
59 /* Find the next half-duplex media */
60 i = Adapter->MediaNumber;
61 while (TRUE)
62 {
63 /* We have reached the end of the media list, try the first media */
64 if (i == 0)
65 {
66 _BitScanReverse(&i, Adapter->MediaBitmap);
67 }
68 else
69 {
70 --i;
71 }
72
73 if ((Adapter->MediaBitmap & (1 << i)) && !MEDIA_IS_FD(i))
74 {
75 return i;
76 }
77 }
78}
79
80VOID
83 _In_ PVOID SystemSpecific1,
87{
89 ULONG DelayMs, MediaNumber;
91
92 UNREFERENCED_PARAMETER(SystemSpecific1);
95
96 if (!(Adapter->Flags & DC_ACTIVE))
97 return;
98
100
101 if (Adapter->MediaNumber == MEDIA_MII)
102 {
103 LinkUp = MediaMiiCheckLink(Adapter);
104
105 DelayMs = 5000;
106 }
107 else
108 {
109 LinkUp = MediaGprCheckLink(Adapter);
110
111 /* This media is unconnected, try the next media */
112 if (!LinkUp && !MEDIA_IS_FIXED(Adapter))
113 {
114 MediaNumber = MediaGprNextMedia(Adapter);
115
116 if (Adapter->MediaNumber != MediaNumber)
117 {
118 Adapter->MediaNumber = MediaNumber;
119 MediaGprSelect(Adapter);
120 }
121
122 DelayMs = 3000;
123 }
124 else
125 {
126 /* If we are forcing media, then we need to poll the media less frequently */
127 DelayMs = 5000;
128 }
129 }
130
132
134
135 NdisMSetTimer(&Adapter->MediaMonitorTimer, DelayMs);
136}
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 MediaMonitor21140Dpc
Definition: dc21x4.h:499
VOID MediaGprSelect(_In_ PDC21X4_ADAPTER Adapter)
Definition: media.c:303
VOID MediaIndicateConnect(_In_ PDC21X4_ADAPTER Adapter, _In_ BOOLEAN LinkUp)
Definition: media.c:17
BOOLEAN MediaMiiCheckLink(_In_ PDC21X4_ADAPTER Adapter)
Definition: media.c:141
@ DcCsr12_Gpio
Definition: dc21x4hw.h:187
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
VOID EXPORT NdisMSetTimer(IN PNDIS_MINIPORT_TIMER Timer, IN UINT MillisecondsToDelay)
Definition: time.c:272
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask)
Definition: intrin_arm.h:180
static ULONG MediaGprNextMedia(_In_ PDC21X4_ADAPTER Adapter)
Definition: media140.c:48
static BOOLEAN MediaGprCheckLink(_In_ PDC21X4_ADAPTER Adapter)
Definition: media140.c:18
#define MEDIA_MII
Definition: media.h:67
#define MEDIA_IS_FIXED(Adapter)
Definition: media.h:126
#define MEDIA_IS_FD(MediaNumber)
Definition: media.h:106
#define MEDIA_FD_MASK
Definition: media.h:77
#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
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
@ LinkUp
Definition: srb.h:741
#define TRACE(s)
Definition: solgame.cpp:4
DECLSPEC_CACHEALIGN NDIS_SPIN_LOCK ModeLock
Definition: dc21x4.h:161
ULONG MediaNumber
Definition: dc21x4.h:174
NDIS_MINIPORT_TIMER MediaMonitorTimer
Definition: dc21x4.h:181
ULONG Flags
Definition: dc21x4.h:119
ULONG LinkMask
Definition: media.h:28
ULONG Polarity
Definition: media.h:29
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG
Definition: typedefs.h:59