ReactOS 0.4.16-dev-297-gc569aee
phy.c File Reference
#include "dc21x4.h"
#include <debug.h>
Include dependency graph for phy.c:

Go to the source code of this file.

Macros

#define MII_READ(Adapter, Data)
 
#define MII_WRITE(Adapter, Value)
 

Functions

static VOID MiiMdioPacket (_In_ PDC21X4_ADAPTER Adapter, _In_ ULONG Sequence, _In_ ULONG BitCount)
 
static ULONG MiiMdioShiftIn (_In_ PDC21X4_ADAPTER Adapter)
 
static VOID MiiMdioClearExtraBits (_In_ PDC21X4_ADAPTER Adapter)
 
BOOLEAN MiiWrite (_In_ PDC21X4_ADAPTER Adapter, _In_ ULONG PhyAddress, _In_ ULONG RegAddress, _In_ ULONG Data)
 
BOOLEAN MiiRead (_In_ PDC21X4_ADAPTER Adapter, _In_ ULONG PhyAddress, _In_ ULONG RegAddress, _Out_ PULONG Data)
 
static VOID HpnaSpiClose (_In_ PDC21X4_ADAPTER Adapter)
 
static VOID HpnaSpiShiftOut (_In_ PDC21X4_ADAPTER Adapter, _In_ ULONG Sequence, _In_ ULONG BitCount)
 
static VOID HpnaWrite (_In_ PDC21X4_ADAPTER Adapter, _In_ ULONG RegAddress, _In_ ULONG Data)
 
VOID HpnaPhyInit (_In_ PDC21X4_ADAPTER Adapter)
 
BOOLEAN DcFindMiiPhy (_In_ PDC21X4_ADAPTER Adapter)
 

Macro Definition Documentation

◆ MII_READ

#define MII_READ (   Adapter,
  Data 
)
Value:
do { \
NdisStallExecution(2); \
} while (0)
FORCEINLINE ULONG DC_READ(_In_ PDC21X4_ADAPTER Adapter, _In_ DC_CSR Register)
Definition: dc21x4.h:262
@ DcCsr9_SerialInterface
Definition: dc21x4hw.h:183

Definition at line 16 of file phy.c.

◆ MII_WRITE

#define MII_WRITE (   Adapter,
  Value 
)
Value:
do { \
DC_WRITE((Adapter), DcCsr9_SerialInterface, Value); \
NdisStallExecution(2); \
} while (0)
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Definition at line 22 of file phy.c.

Function Documentation

◆ DcFindMiiPhy()

BOOLEAN DcFindMiiPhy ( _In_ PDC21X4_ADAPTER  Adapter)

Definition at line 217 of file phy.c.

219{
220 ULONG Phy;
221
222 PAGED_CODE();
223
224 /* Look for the first connected PHY */
225 for (Phy = 1; Phy <= MII_MAX_PHY_ADDRESSES; ++Phy)
226 {
227 ULONG PhyAddress = Phy % MII_MAX_PHY_ADDRESSES; /* Check the PHY 0 last */
228 ULONG MiiStatus;
229#if DBG
230 ULONG PhyIdLow, PhyIdHigh, MiiControl, MiiAdvertise;
231#endif
232
233 /*
234 * Read the status register. Some PHYs, such as the ML6692,
235 * don't implement the IEEE ID registers.
236 */
237 if (!MiiRead(Adapter, PhyAddress, MII_STATUS, &MiiStatus))
238 continue;
239 if (MiiStatus == 0xFFFF || MiiStatus == 0)
240 continue;
241
242#if DBG
243 MiiRead(Adapter, PhyAddress, MII_PHY_ID1, &PhyIdLow);
244 MiiRead(Adapter, PhyAddress, MII_PHY_ID2, &PhyIdHigh);
245 MiiRead(Adapter, PhyAddress, MII_CONTROL, &MiiControl);
246 MiiRead(Adapter, PhyAddress, MII_AUTONEG_ADVERTISE, &MiiAdvertise);
247
248 INFO_VERB("Found PHY at address %u: ID %04lx:%04lx, Ctrl %04lx, Status %04lx, Adv %04lx\n",
249 PhyAddress,
250 PhyIdLow,
251 PhyIdHigh,
252 MiiControl,
253 MiiStatus,
254 MiiAdvertise);
255#endif
256
257 Adapter->PhyAddress = PhyAddress;
258
259 return TRUE;
260 }
261
262 return FALSE;
263}
#define PAGED_CODE()
BOOLEAN MiiRead(_In_ PDC21X4_ADAPTER Adapter, _In_ ULONG PhyAddress, _In_ ULONG RegAddress, _Out_ PULONG Data)
Definition: phy.c:101
#define MII_STATUS
Definition: dc21x4hw.h:566
#define MII_PHY_ID2
Definition: dc21x4hw.h:570
#define MII_MAX_PHY_ADDRESSES
Definition: dc21x4hw.h:551
#define MII_AUTONEG_ADVERTISE
Definition: dc21x4hw.h:571
#define MII_PHY_ID1
Definition: dc21x4hw.h:569
#define MII_CONTROL
Definition: dc21x4hw.h:556
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define INFO_VERB
Definition: debug.h:90
uint32_t ULONG
Definition: typedefs.h:59

Referenced by DcInitialize().

◆ HpnaPhyInit()

VOID HpnaPhyInit ( _In_ PDC21X4_ADAPTER  Adapter)

Definition at line 194 of file phy.c.

196{
197 ULONG SiaConn, i;
198
199 PAGED_CODE();
200
201 /* Select the HPNA interface */
202 SiaConn = DC_READ(Adapter, DcCsr13_SiaConnectivity);
203 SiaConn |= DC_SIA_CONN_HPNA;
204 DC_WRITE(Adapter, DcCsr13_SiaConnectivity, SiaConn);
205
206 for (i = 0; i < RTL_NUMBER_OF(Adapter->HpnaRegister); ++i)
207 {
208 if (Adapter->HpnaInitBitmap & (1 << i))
209 {
210 HpnaWrite(Adapter, i, Adapter->HpnaRegister[i]);
211 }
212 }
213}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
static VOID HpnaWrite(_In_ PDC21X4_ADAPTER Adapter, _In_ ULONG RegAddress, _In_ ULONG Data)
Definition: phy.c:174
#define DC_WRITE(Adapter, Register, Value)
Definition: dc21x4.h:272
@ DcCsr13_SiaConnectivity
Definition: dc21x4hw.h:189
#define DC_SIA_CONN_HPNA
Definition: dc21x4hw.h:450
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

Referenced by DcSetupAdapter().

◆ HpnaSpiClose()

static VOID HpnaSpiClose ( _In_ PDC21X4_ADAPTER  Adapter)
static

Definition at line 135 of file phy.c.

137{
138 PAGED_CODE();
139
140 DC_WRITE(Adapter, DcCsr9_SerialInterface, 0);
142}
#define DC_SERIAL_SPI_SK
Definition: dc21x4hw.h:389

Referenced by HpnaWrite().

◆ HpnaSpiShiftOut()

static VOID HpnaSpiShiftOut ( _In_ PDC21X4_ADAPTER  Adapter,
_In_ ULONG  Sequence,
_In_ ULONG  BitCount 
)
static

Definition at line 147 of file phy.c.

151{
152 LONG i;
153
154 PAGED_CODE();
155
156 DC_WRITE(Adapter, DcCsr9_SerialInterface, 0);
158
159 for (i = BitCount - 1; i >= 0; --i)
160 {
161 ULONG DataIn = ((Sequence >> i) & 1) << DC_SERIAL_SPI_DI_SHIFT;
162
165 }
166
167 DC_WRITE(Adapter, DcCsr9_SerialInterface, 0);
169}
#define DC_SERIAL_SPI_CS
Definition: dc21x4hw.h:388
#define DC_SERIAL_SPI_DI_SHIFT
Definition: dc21x4hw.h:397
long LONG
Definition: pedump.c:60

Referenced by HpnaWrite().

◆ HpnaWrite()

static VOID HpnaWrite ( _In_ PDC21X4_ADAPTER  Adapter,
_In_ ULONG  RegAddress,
_In_ ULONG  Data 
)
static

Definition at line 174 of file phy.c.

178{
179 PAGED_CODE();
180
182 HpnaSpiClose(Adapter);
183
184 HpnaSpiShiftOut(Adapter,
185 (Data << 16) |
186 (RegAddress << 8) |
188 RTL_BITS_OF(UCHAR) * 3);
189 HpnaSpiClose(Adapter);
190}
static VOID HpnaSpiShiftOut(_In_ PDC21X4_ADAPTER Adapter, _In_ ULONG Sequence, _In_ ULONG BitCount)
Definition: phy.c:147
static VOID HpnaSpiClose(_In_ PDC21X4_ADAPTER Adapter)
Definition: phy.c:135
#define DC_SPI_BYTE_WRITE_OPERATION
Definition: dc21x4hw.h:527
#define DC_SPI_SET_WRITE_ENABLE
Definition: dc21x4hw.h:530
#define RTL_BITS_OF(sizeOfArg)
Definition: ntbasedef.h:676
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by HpnaPhyInit().

◆ MiiMdioClearExtraBits()

static VOID MiiMdioClearExtraBits ( _In_ PDC21X4_ADAPTER  Adapter)
static

Definition at line 70 of file phy.c.

72{
75}
#define MII_WRITE(Adapter, Value)
Definition: phy.c:22
#define DC_SERIAL_MII_MDC
Definition: dc21x4hw.h:382
#define DC_SERIAL_MII_MII
Definition: dc21x4hw.h:384

Referenced by MiiRead(), and MiiWrite().

◆ MiiMdioPacket()

static VOID MiiMdioPacket ( _In_ PDC21X4_ADAPTER  Adapter,
_In_ ULONG  Sequence,
_In_ ULONG  BitCount 
)
static

Definition at line 32 of file phy.c.

36{
37 LONG i;
38
39 for (i = BitCount - 1; i >= 0; --i)
40 {
41 ULONG Mdo = ((Sequence >> i) & 1) << DC_SERIAL_MII_MDO_SHIFT;
42
43 MII_WRITE(Adapter, Mdo);
44 MII_WRITE(Adapter, Mdo | DC_SERIAL_MII_MDC);
45 }
46}
#define DC_SERIAL_MII_MDO_SHIFT
Definition: dc21x4hw.h:395

Referenced by MiiRead(), and MiiWrite().

◆ MiiMdioShiftIn()

static ULONG MiiMdioShiftIn ( _In_ PDC21X4_ADAPTER  Adapter)
static

Definition at line 50 of file phy.c.

52{
53 ULONG i, Csr;
54 ULONG Result = 0;
55
56 for (i = 0; i < RTL_BITS_OF(USHORT); ++i)
57 {
60
61 MII_READ(Adapter, &Csr);
62 Result = (Result << 1) | ((Csr >> DC_SERIAL_MII_MDI_SHIFT) & 1);
63 }
64
65 return Result;
66}
#define MII_READ(Adapter, Data)
Definition: phy.c:16
#define DC_SERIAL_MII_MDI_SHIFT
Definition: dc21x4hw.h:396
unsigned short USHORT
Definition: pedump.c:61
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by MiiRead().

◆ MiiRead()

BOOLEAN MiiRead ( _In_ PDC21X4_ADAPTER  Adapter,
_In_ ULONG  PhyAddress,
_In_ ULONG  RegAddress,
_Out_ PULONG  Data 
)

Definition at line 101 of file phy.c.

106{
107 ULONG Csr;
109
110 MiiMdioPacket(Adapter, MDIO_PREAMBLE, 32);
111 MiiMdioPacket(Adapter,
112 (MDIO_START << 12) |
113 (MDIO_READ << 10) |
114 (PhyAddress << 5) |
115 RegAddress,
116 14);
117
118 /* Turnaround */
119 MiiMdioClearExtraBits(Adapter);
120
121 Csr = DC_READ(Adapter, DcCsr9_SerialInterface);
122 Success = !(Csr & DC_SERIAL_MII_MDI);
123
124 *Data = MiiMdioShiftIn(Adapter);
125
126 /* Idle state */
127 MiiMdioClearExtraBits(Adapter);
128
129 return Success;
130}
unsigned char BOOLEAN
static VOID MiiMdioClearExtraBits(_In_ PDC21X4_ADAPTER Adapter)
Definition: phy.c:70
static ULONG MiiMdioShiftIn(_In_ PDC21X4_ADAPTER Adapter)
Definition: phy.c:50
static VOID MiiMdioPacket(_In_ PDC21X4_ADAPTER Adapter, _In_ ULONG Sequence, _In_ ULONG BitCount)
Definition: phy.c:32
#define MDIO_PREAMBLE
Definition: dc21x4hw.h:549
#define MDIO_START
Definition: dc21x4hw.h:545
#define DC_SERIAL_MII_MDI
Definition: dc21x4hw.h:385
#define MDIO_READ
Definition: dc21x4hw.h:547
@ Success
Definition: eventcreate.c:712

Referenced by DcFindMiiPhy(), FindPhyDevice(), MediaMiiCheckLink(), MediaMiiGetSpeedAndDuplex(), MediaMiiSelect(), MiiGetSpeedAndDuplex(), NvNetInitNIC(), NvNetPhyInit(), NvNetSetSpeedAndDuplex(), PhyInit(), PhyInitCicadaSemiconductor(), PhyInitRealtek8201(), PhyInitRealtek8211c(), PhyInitVitesseSemiconductor(), and PhyReset().

◆ MiiWrite()

BOOLEAN MiiWrite ( _In_ PDC21X4_ADAPTER  Adapter,
_In_ ULONG  PhyAddress,
_In_ ULONG  RegAddress,
_In_ ULONG  Data 
)

Definition at line 78 of file phy.c.

83{
84 MiiMdioPacket(Adapter, MDIO_PREAMBLE, 32);
85 MiiMdioPacket(Adapter,
86 (MDIO_START << 30) |
87 (MDIO_WRITE << 28) |
88 (PhyAddress << 23) |
89 (RegAddress << 18) |
90 (MDIO_TA << 16) |
91 Data,
92 32);
93
94 /* Idle state */
95 MiiMdioClearExtraBits(Adapter);
96
97 return TRUE;
98}
#define MDIO_TA
Definition: dc21x4hw.h:548
#define MDIO_WRITE
Definition: dc21x4hw.h:546

Referenced by MediaMiiSelect(), NvNetInitNIC(), PhyInit(), PhyInitCicadaSemiconductor(), PhyInitRealtek8201(), PhyInitRealtek8211b(), PhyInitRealtek8211c(), PhyInitVitesseSemiconductor(), and PhyReset().