NetBSD Problem Report #8294

Received: (qmail 24292 invoked from network); 30 Aug 1999 11:28:21 -0000
Message-Id: <199908301128.VAA00455@napolitana.cs.mu.OZ.AU>
Date: Mon, 30 Aug 1999 21:28:18 +1000 (EST)
From: kre@munnari.OZ.AU
To: gnats-bugs@gnats.netbsd.org
Subject: 3c905B-TX phy/media detection fixes
X-Send-Pr-Version: 3.95

>Number:         8294
>Category:       kern
>Synopsis:       PHY is not found on recent 3c905B-TX cards
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Aug 30 04:35:00 +0000 1999
>Closed-Date:    Thu Sep 02 20:27:25 +0000 1999
>Last-Modified:  Thu Sep 02 20:28:05 +0000 1999
>Originator:     Robert Elz
>Release:        NetBSD 1.4
>Organization:
University of Melbourne
>Environment:

System: NetBSD napolitana.cs.mu.OZ.AU 1.4 NetBSD 1.4 (LAVENDER) #16: Sat Aug 21 15:34:27 EST 1999 root@napolitana.cs.mu.OZ.AU:/usr/src/sys/arch/alpha/compile/LAVENDER alpha


>Description:
	Recent 3Com 3C905B-TX cards are recognised by the kernel,
	but no PHY is located, hence no media are available, and
	while the interface appears to (kind of0 work, no packets
	are sent or received.

>How-To-Repeat:
	Obtain a recent 3C905B-TX, install it, configure it, and boot.
	Observe the boot messages as ...

	ex1 at pci0 dev 15 function 0: 3Com 3c905B-TX 10/100 Ethernet
	ex1: interrupting at irq 5
	ex1: MAC address 00:10:5a:76:e9:b4

	where what is expected is

	ex0 at pci0 dev 9 function 0: 3Com 3c905B-TX 10/100 Ethernet
	ex0: interrupting at eb164 irq 3
	ex0: MAC address 00:10:5a:76:5f:06
	ukphy0 at ex0 phy 24: Generic IEEE 802.3u media interface
	ukphy0: OUI 0x001018, model 0x0012, rev. 0
	ukphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto

	or something like that (yes, Ok, those are from different boards
	in different systems, but that's what happens anyway...).

>Fix:

	Apply the following patch in /sys/dev/ic

	There are three parts to this patch - first a one line
	addition to elinkxlreg.h to define one new symbol (other
	values like this are in elink3reg.h - but this is a 905B
	only define, other such defines are in the xl header file)

	Then there's code which writes the internal config register
	depending upon the media capabilities of the board.

	And last, the low leval phy i/o routines were altered a bit.

	The first of those 3 is just to make the second compile (and
	avoid magic numbers in .c files).   Both of the others seem
	necessary to get this board to recognise the PHY.   Neither
	alone is sufficient.   However, the 3rd change contains a
	number of smaller parts (changing which bits are set, changing
	the order things are done, and inserting delays) - whether all
	of that is needed or not I don't know, I have tested only all
	or nothing of that set.

	All of this comes from the FreeBSD driver (if_xl.c) from the
	FreeBSD 3.2 sources.   There are many other differences (of
	some substance, and vastly many more of form only) between the
	NetNBSD and FreeBSD drivers.   Someone with access to 3Com doc
	really needs to do a lot of hard looking at this driver.

	This has been tested on i386 (with both 3C900B-TPC and 3C905B-TX
	cards - nothing here should have affected the 3C900 code, and
	none of it seems to), and on alpha (3C905B-TX only).   Testing
	is needed on other cards of the family.   Also, so far I have
	tested only 10BaseT connections (hdx).   This fix was developed
	on an i386 platform, then once working there, was copied to the
	alpha, where it worked first time.

	ps: take no notice of the various dates below, the alpha
	that generated the diffs was switched back & forth between
	FreeBSD and NetBSD while this was being done (FreeBSD was
	needed to get the fixed files across the net) -- the two of
	them fail to agree on how the date should be represented in
	the TODR.  Whatever the dates look like, these diffs are not
	reversed, or anything strange like that.


*** elinkxlreg.h.was	Wed Nov  4 11:29:29 1998
--- elinkxlreg.h	Sat Aug 21 15:31:36 1999
***************
*** 177,182 ****
--- 177,184 ----
  #define CONFIG_XCVR_SEL		(u_int16_t) 0x00f0
  #define CONFIG_XCVR_SEL_SHIFT	4

+ #define	ELINKMEDIA_AUTO		8
+ 
  #define CONFIG_AUTOSEL		(u_int16_t) 0x0100
  #define CONFIG_AUTOSEL_SHIFT	8





*** elinkxl.c.was	Mon Aug 30 20:47:16 1999
--- elinkxl.c	Sat Aug 21 15:31:36 1999
***************
*** 382,387 ****
--- 382,403 ----
  		/*
  		 * Find PHY, extract media information from it.
  		 */
+ 		u_int32_t icfg;
+ 
+ 		/* stolen from FreeBSD xl driver */
+ 		GO_WINDOW(3);
+ 		icfg = bus_space_read_4(iot, ioh, ELINK_W3_INTERNAL_CONFIG);
+ 		icfg &= ~(CONFIG_XCVR_SEL << 16);
+ 		if (val & (ELINK_MEDIACAP_MII | ELINK_MEDIACAP_100BASET4))
+ 			icfg |= ELINKMEDIA_MII << (CONFIG_XCVR_SEL_SHIFT + 16);
+ 		if (val & ELINK_MEDIACAP_100BASETX)
+ 			icfg |= ELINKMEDIA_AUTO << (CONFIG_XCVR_SEL_SHIFT + 16);
+ 		if (val & ELINK_MEDIACAP_100BASEFX)
+ 			icfg |= ELINKMEDIA_100BASE_FX 
+ 				<< (CONFIG_XCVR_SEL_SHIFT + 16);
+ 		bus_space_write_4(iot, ioh, ELINK_W3_INTERNAL_CONFIG, icfg);
+ 		/* end steal */
+ 
  		mii_phy_probe(&sc->sc_dev, &sc->ex_mii, 0xffffffff);
  		if (LIST_FIRST(&sc->ex_mii.mii_phys) == NULL) {
  			ifmedia_add(&sc->ex_mii.mii_media, IFM_ETHER|IFM_NONE,
***************
*** 1714,1746 ****

  	bus_space_write_2(sc->sc_iot, sc->sc_ioh, ELINK_W4_PHYSMGMT, 0);

! 	ex_mii_clrbit(sc, ELINK_PHY_DIR);
          for (i = 0; i < 32; i++) {
-                 ex_mii_clrbit(sc, ELINK_PHY_CLK);
                  ex_mii_setbit(sc, ELINK_PHY_CLK);
          }
  	ex_mii_writebits(sc, MII_COMMAND_START, 2);
  	ex_mii_writebits(sc, MII_COMMAND_READ, 2);
  	ex_mii_writebits(sc, phy, 5);
  	ex_mii_writebits(sc, reg, 5);

! 	ex_mii_clrbit(sc, ELINK_PHY_DIR);
! 	ex_mii_clrbit(sc, ELINK_PHY_CLK);
  	ex_mii_setbit(sc, ELINK_PHY_CLK);
! 	ex_mii_clrbit(sc, ELINK_PHY_CLK);

  	err = ex_mii_readbit(sc, ELINK_PHY_DATA);
- 	ex_mii_setbit(sc, ELINK_PHY_CLK);

  	for (i = 0; i < 16; i++) {
  		val <<= 1;
  		ex_mii_clrbit(sc, ELINK_PHY_CLK);
  		if (err == 0 && ex_mii_readbit(sc, ELINK_PHY_DATA))
  				val |= 1;
  		ex_mii_setbit(sc, ELINK_PHY_CLK);
  	}
  	ex_mii_clrbit(sc, ELINK_PHY_CLK);
  	ex_mii_setbit(sc, ELINK_PHY_CLK);

  	GO_WINDOW(1);

--- 1730,1775 ----

  	bus_space_write_2(sc->sc_iot, sc->sc_ioh, ELINK_W4_PHYSMGMT, 0);

! 	ex_mii_setbit(sc, ELINK_PHY_DIR);
! 	delay(1);
! 	ex_mii_setbit(sc, ELINK_PHY_DIR|ELINK_PHY_DATA);
! 	delay(1);
! 
          for (i = 0; i < 32; i++) {
                  ex_mii_setbit(sc, ELINK_PHY_CLK);
+ 		delay(1);
+                 ex_mii_clrbit(sc, ELINK_PHY_CLK);
+ 		delay(1);
          }
  	ex_mii_writebits(sc, MII_COMMAND_START, 2);
  	ex_mii_writebits(sc, MII_COMMAND_READ, 2);
  	ex_mii_writebits(sc, phy, 5);
  	ex_mii_writebits(sc, reg, 5);

! 	ex_mii_clrbit(sc, ELINK_PHY_DATA|ELINK_PHY_CLK);
! 	delay(1);
  	ex_mii_setbit(sc, ELINK_PHY_CLK);
! 	delay(1);
! 	ex_mii_clrbit(sc, ELINK_PHY_DIR|ELINK_PHY_CLK);
! 	delay(1);
! 	ex_mii_setbit(sc, ELINK_PHY_CLK);
! 	delay(1);

  	err = ex_mii_readbit(sc, ELINK_PHY_DATA);

  	for (i = 0; i < 16; i++) {
  		val <<= 1;
  		ex_mii_clrbit(sc, ELINK_PHY_CLK);
+ 		delay(1);
  		if (err == 0 && ex_mii_readbit(sc, ELINK_PHY_DATA))
  				val |= 1;
  		ex_mii_setbit(sc, ELINK_PHY_CLK);
+ 		delay(1);
  	}
  	ex_mii_clrbit(sc, ELINK_PHY_CLK);
+ 	delay(1);
  	ex_mii_setbit(sc, ELINK_PHY_CLK);
+ 	delay(1);

  	GO_WINDOW(1);

***************
*** 1756,1770 ****
  	int i;

  	ex_mii_setbit(sc, ELINK_PHY_DIR);
  	for (i = 1 << (nbits -1); i; i = i >>  1) {
- 		ex_mii_clrbit(sc, ELINK_PHY_CLK);
- 		ex_mii_readbit(sc, ELINK_PHY_CLK);
  		if (data & i)
  			ex_mii_setbit(sc, ELINK_PHY_DATA);
  		else
  			ex_mii_clrbit(sc, ELINK_PHY_DATA);
  		ex_mii_setbit(sc, ELINK_PHY_CLK);
- 		ex_mii_readbit(sc, ELINK_PHY_CLK);
  	}
  }

--- 1785,1801 ----
  	int i;

  	ex_mii_setbit(sc, ELINK_PHY_DIR);
+ 	ex_mii_clrbit(sc, ELINK_PHY_CLK);
+ 
  	for (i = 1 << (nbits -1); i; i = i >>  1) {
  		if (data & i)
  			ex_mii_setbit(sc, ELINK_PHY_DATA);
  		else
  			ex_mii_clrbit(sc, ELINK_PHY_DATA);
+ 		delay(1);
+ 		ex_mii_clrbit(sc, ELINK_PHY_CLK);
+ 		delay(1);
  		ex_mii_setbit(sc, ELINK_PHY_CLK);
  	}
  }

***************
*** 1780,1789 ****

  	GO_WINDOW(4);

! 	ex_mii_clrbit(sc, ELINK_PHY_DIR);
  	for (i = 0; i < 32; i++) {
! 		ex_mii_clrbit(sc, ELINK_PHY_CLK);
! 		ex_mii_setbit(sc, ELINK_PHY_CLK);
  	}
  	ex_mii_writebits(sc, MII_COMMAND_START, 2);
  	ex_mii_writebits(sc, MII_COMMAND_WRITE, 2);
--- 1811,1825 ----

  	GO_WINDOW(4);

! 	ex_mii_setbit(sc, ELINK_PHY_DIR);
! 	delay(1);
! 	ex_mii_setbit(sc, ELINK_PHY_DIR|ELINK_PHY_DATA);
! 	delay(1);
  	for (i = 0; i < 32; i++) {
!                 ex_mii_setbit(sc, ELINK_PHY_CLK);
! 		delay(1);
!                 ex_mii_clrbit(sc, ELINK_PHY_CLK);
! 		delay(1);
  	}
  	ex_mii_writebits(sc, MII_COMMAND_START, 2);
  	ex_mii_writebits(sc, MII_COMMAND_WRITE, 2);
***************
*** 1792,1799 ****
  	ex_mii_writebits(sc, MII_COMMAND_ACK, 2);
  	ex_mii_writebits(sc, data, 16);

- 	ex_mii_clrbit(sc, ELINK_PHY_CLK);
  	ex_mii_setbit(sc, ELINK_PHY_CLK);

  	GO_WINDOW(1);
  }
--- 1828,1838 ----
  	ex_mii_writebits(sc, MII_COMMAND_ACK, 2);
  	ex_mii_writebits(sc, data, 16);

  	ex_mii_setbit(sc, ELINK_PHY_CLK);
+ 	delay(1);
+ 	ex_mii_clrbit(sc, ELINK_PHY_CLK);
+ 	delay(1);
+ 	ex_mii_clrbit(sc, ELINK_PHY_DIR);

  	GO_WINDOW(1);
  }
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: fvdl 
State-Changed-When: Thu Sep 2 13:27:25 PDT 1999 
State-Changed-Why:  
Fixed through patch supplied by submitter of PR> 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.