Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Dec 1998 16:57:04 -0500 (EST)
From:      Bill Paul <wpaul@skynet.ctr.columbia.edu>
To:        hackers@FreeBSD.ORG
Subject:   Code review request (new MII support)
Message-ID:  <199812092157.QAA22754@skynet.ctr.columbia.edu>

next in thread | raw e-mail | index | archive | help
The past couple of days I've been experimenting with the MII/PHY
support code from NetBSD (sys/dev/mii). This code provides support
for MII transceivers attached to ethernet controllers. Many (hell, most)
of the fast ethernet controllers on the market today include support
for MII-compliant transceivers. At the moment, all of the drivers for
ethernet cards that use MII transceivers have their own MII support
code, and handle autonegotiation and media selection themselves. The
result is a fair amount of duplicated code. The NetBSD MII support
(which I think is meant to emulate similar support in BSD/OS) allows
ethernet drivers to avoid having to deal with the gruntwork of
autonegotiation and media selection and reduces code duplication. 
I also allows PHYs drivers to handle quirks themselves rather than
having to put hacks directly into ethernet drivers, and makes it
easier to deal with vendors who like to mix and match controllers
and PHYs a lot.

Getting it to work properly on FreeBSD was complicated by the fact that 
NetBSD makes copious use of <sys/device.h> and src/kern/subr_autoconf.c 
for device configuration, whereas we have all but forgotten about them. 
(I assume this is because somebody out there has an incredibly spiffy 
replacement that will do everything they do plus more, right? Right? 
Uh... hello, is this thing on? *tap* *tap*)

Anyway. I have it working okay for now. One of the things I had to do
was substitute struct ifnet for struct device in a few places where
the MII code expects to find the device struct for its parent device
(in this case, an ethernet driver). I also kludged up a glue module
to take the place of the autoconfig support that we don't have. My
version uses a linker set much like the PCI drivers: each PHY driver
adds its set of probe/attach routines to the linker set with DATA_SET(),
and the match routine cycles through them all to find a driver that
supports a given PHY.

The result looks something like this:

pn0: <82c168/82c169 PNIC 10/100BaseTX> rev 0x21 int a irq 11 on pci0.10.0
pn0: Ethernet address: 00:a0:cc:3a:5f:fe
mii0: OUI 0x1e0400 model 0x0000 rev 0 at pn0 phy 1
lxtphy0: LXT970 10/100 media interface, rev. 0
lxtphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
vr0: <VIA VT3043 Rhine I 10/100BaseTX> rev 0x06 int a irq 10 on pci0.12.0
vr0: Ethernet address: 00:80:c8:4b:9c:90
mii1: OUI 0x006040 model 0x0000 rev 0 at vr0 phy 8
dvphy0: Davicom 10/100 media interface, rev. 0
dvphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto

What I would like to do is add this support to 3.0-current and then
convert the drivers that need MII/PHY support to use it. I have a
copy of the code at http://www.freebsd.org/~wpaul/MII/mii.tar.gz.
This includes the core MII code, PHY drivers, glue routines and
two sample ethernet drivers converted to use the MII support (if_pn
and if_vr). In order to use the code, you have to do the following:

- mkdir /sys/dev/mii
- copy everything except if_pn* and if_vr* to /sys/dev/mii
- append files.FreeBSD to /sys/conf/files
- copy if_pn* and if_vr* to /sys/pci
- add the following to your kernel config file:

	controller mii0
	device pn0
	device vr0

What I would like are comments and suggestions, particularly about
how to improve the way the code is configured into the kernel; what I
did for now is just a quick hack to get everything built.

-Bill

-- 
=============================================================================
-Bill Paul            (212) 854-6020 | System Manager, Master of Unix-Fu
Work:         wpaul@ctr.columbia.edu | Center for Telecommunications Research
Home:  wpaul@skynet.ctr.columbia.edu | Columbia University, New York City
=============================================================================
 "It is not I who am crazy; it is I who am mad!" - Ren Hoek, "Space Madness"
=============================================================================

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199812092157.QAA22754>