Subject: Re: re(4) causes stuck in boot
To: None <F.Lorenzen@gmx.de>
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
List: current-users
Date: 01/29/2007 21:30:52
F.Lorenzen@gmx.de wrote:

> > Hmm, it seems EEPROM on 8169S requires more delay.
> > How about this one? (tested on 8169S and 8139C, but not on 8139C-plus)
 :
> Well done. Thanks a lot.
> 
> re0 at pci0 dev 9 function 0: RealTek 8169SC/8110SC Single-chip Gigabit
> Ethernet
> re0: interrupting at irq 11
> re0: Ethernet address 00:30:18:b0:2b:11
> re0: using 256 tx descriptors

Thank you for your testing. I've committed the fix and
will send a pullup request to netbsd-4.

> There is one issue left i noticed during Testing:
> If I enable only the second Card in Bios, which I don't do normally, re
> says: 'can't map i/o space' and doesn't configure the Card.

I guess it's a BIOS problem (it doesn't initialize PCI I/O space
properly but only does PCI MEM space in that case).
Maybe you could remove "#define RE_USEIOSPACE" in if_re_pci.c
to make it work, but could you please try the attached patch too?
(to see if it's actually worth on such motherboard)

> And again OpenBSD can handle this.

OpenBSD's driver seems to use PCI MEM space by default.
(I'm not sure why FreeBSD's driver wanted USEIOSPACE though)
---
Izumi Tsutsui


Index: dev/pci/if_re_pci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_re_pci.c,v
retrieving revision 1.21
diff -u -r1.21 if_re_pci.c
--- dev/pci/if_re_pci.c	24 Nov 2006 19:38:55 -0000	1.21
+++ dev/pci/if_re_pci.c	28 Jan 2007 13:17:55 -0000
@@ -76,11 +76,6 @@
 #include <dev/pci/pcivar.h>
 #include <dev/pci/pcidevs.h>
 
-/*
- * Default to using PIO access for this driver.
- */
-#define RE_USEIOSPACE
-
 #include <dev/ic/rtl81x9reg.h>
 #include <dev/ic/rtl81x9var.h>
 #include <dev/ic/rtl8169var.h>
@@ -180,13 +175,14 @@
 static int
 re_pci_match(struct device *parent, struct cfdata *match, void *aux)
 {
-	const struct rtk_type		*t;
+	const struct rtk_type	*t;
 	struct pci_attach_args	*pa = aux;
-	bus_space_tag_t		rtk_btag;
-	bus_space_handle_t	rtk_bhandle;
-	bus_size_t		bsize;
+	bus_space_tag_t		iot, memt, bst;
+	bus_space_handle_t	ioh, memh, bsh;
+	bus_size_t		memsize, iosize, bsize;
 	u_int32_t		hwrev;
 	pcireg_t subid;
+	boolean_t ioh_valid, memh_valid;
 
 	subid = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
 
@@ -206,24 +202,25 @@
 			 * Temporarily map the I/O space
 			 * so we can read the chip ID register.
 			 */
-#ifdef RE_USEIOSPACE
-			if (pci_mapreg_map(pa, RTK_PCI_LOIO,
-			    PCI_MAPREG_TYPE_IO, 0, &rtk_btag,
-			    &rtk_bhandle, NULL, &bsize)) {
-				aprint_error("can't map i/o space\n");
-				return 0;
-			}
-#else
-			if (pci_mapreg_map(pa, RTK_PCI_LOMEM,
-			    PCI_MAPREG_TYPE_MEM, 0, &rtk_btag,
-			    &rtk_bhandle, NULL, &bsize)) {
-				aprint_error("can't map mem space\n");
+			ioh_valid = (pci_mapreg_map(pa, RTK_PCI_LOIO,
+			    PCI_MAPREG_TYPE_IO, 0, &iot, &ioh,
+			    NULL, &iosize) == 0);
+			memh_valid = (pci_mapreg_map(pa, RTK_PCI_LOMEM,
+			    PCI_MAPREG_TYPE_MEM, 0, &memt, &memh,
+			    NULL, &memsize) == 0);
+			if (ioh_valid) {
+				bst = iot;
+				bsh = ioh;
+				bsize = iosize;
+			} else if (memh_valid) {
+				bst = memt;
+				bsh = memh;
+				bsize = memsize;
+			} else
 				return 0;
-			}
-#endif
-			hwrev = bus_space_read_4(rtk_btag, rtk_bhandle,
-			    RTK_TXCFG) & RTK_TXCFG_HWREV;
-			bus_space_unmap(rtk_btag, rtk_bhandle, bsize);
+			hwrev = bus_space_read_4(bst, bsh, RTK_TXCFG) &
+			    RTK_TXCFG_HWREV;
+			bus_space_unmap(bst, bsh, bsize);
 			if (t->rtk_basetype == hwrev)
 				return 2;	/* defeat rtk(4) */
 		}
@@ -244,11 +241,14 @@
 	const char *intrstr = NULL;
 	const struct rtk_type	*t;
 	const struct rtk_hwrev	*hw_rev;
-	int			hwrev;
+	uint32_t		hwrev;
 	int			error = 0;
 	int			pmreg;
+	boolean_t		ioh_valid, memh_valid;
 	pcireg_t		command;
-	bus_size_t		bsize;
+	bus_space_tag_t		iot, memt;
+	bus_space_handle_t	ioh, memh;
+	bus_size_t		iosize, memsize, bsize;
 
 
 	/*
@@ -287,19 +287,23 @@
 	command |= PCI_COMMAND_MASTER_ENABLE;
 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command);
 
-#ifdef RE_USEIOSPACE
-	if (pci_mapreg_map(pa, RTK_PCI_LOIO, PCI_MAPREG_TYPE_IO, 0,
-	    &sc->rtk_btag, &sc->rtk_bhandle, NULL, &bsize)) {
-		aprint_error("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
+	ioh_valid = (pci_mapreg_map(pa, RTK_PCI_LOIO, PCI_MAPREG_TYPE_IO, 0,
+	    &iot, &ioh, NULL, &iosize) == 0);
+	memh_valid = (pci_mapreg_map(pa, RTK_PCI_LOMEM, PCI_MAPREG_TYPE_MEM, 0,
+	    &memt, &memh, NULL, &memsize) == 0);
+	if (ioh_valid) {
+		sc->rtk_btag = iot;
+		sc->rtk_bhandle = ioh;
+		bsize = iosize;
+	} else if (memh_valid) {
+		sc->rtk_btag = memt;
+		sc->rtk_bhandle = memh;
+		bsize = memsize;
+	} else {
+		aprint_error("%s: can't map registers\n", sc->sc_dev.dv_xname);
 		return;
 	}
-#else
-	if (pci_mapreg_map(pa, RTK_PCI_LOMEM, PCI_MAPREG_TYPE_MEM, 0,
-	    &sc->rtk_btag, &sc->rtk_bhandle, NULL, &bsize)) {
-		aprint_error("%s: can't map mem space\n", sc->sc_dev.dv_xname);
-		return;
-	}
-#endif
+
 	t = re_devs;
 	hwrev = CSR_READ_4(sc, RTK_TXCFG) & RTK_TXCFG_HWREV;