views:

359

answers:

3

I'm looking for the best way to interpret the standard (well, standardish) Ethernet PHY registers, to determine the speed that an Ethernet link is actually running at. (e.g. 10/100/1000 and full/half-duplex)

I daresay that this is to be found in the source of things like Linux, and I'm just off to look there now, but if anyone has a good reference I'd be interested.

What I'm interested in is if it actually linked and what it linked at, rather than the vast sea of possibilities that each end has advertised at the outset.

+1  A: 

It would help if you gave us some context to work with. On what operating system do you need to do this? What type of program -- application, system service, driver? Do you need to do it only on particular hardware, or generically for any network card?

Most operating systems have some sort of system management API that will let you query stuff like this. On Windows this is called Windows Management Instrumentation or WMI. In that API you would look for the MSNdis_MediaConnectStatus object to find out if a particular interface is connected or not. Some tips on exploring the object hierarchy for network cards are included in NDIS WMI Notes on the ndis.com site.

Tim Farley
+1  A: 

Thanks for the answer. It's intended as a language and platform agnostic question, because pretty much all MII/GMII Ethernet PHYs have the same basic registers. I happen to be on an embedded platform.

But I found a sensible sequence which was good enough for my restricted application by looking at various bits of Linux driver source - it's basically:

Check for link-up in basic-status (0x1) If the link's up then check for negotiation-complete in basic status (0x1) If the negotiation's complete then check for 1G in the 1000M-status register (0xa) If you've not got 1G, then you've got 100M. (That's not a general rule, but it applies in this application)

Maybe this was really a hardware question rather than a software one...

Will Dean
Agreed - more of a hardware question
Thelema
+1  A: 

To help you looking at how the Linux kernel does it: While each driver can do its own thing, there is a generic version which is supposed to be used when the chip follows the standard closely enough: Generic Media Independent Interface device support.

CesarB
Why the downvote? I know he already mentioned Linux, but I pointed to exactly where in the Linux kernel source code this could be found.
CesarB