Subject: Re: CVS commit: src/sys/dev/pci
To: None <jdolecek@netbsd.org>
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
List: source-changes
Date: 03/05/2005 20:35:54
In article <20050220183433.53CDC2DA1D@cvs.netbsd.org>
jdolecek@netbsd.org wrote:

> Modified Files:
> 	src/sys/dev/pci: files.pci
> Added Files:
> 	src/sys/dev/pci: if_vge.c if_vgereg.h if_vgevar.h
> 
> Log Message:
> Add device driver support for the VIA Networking Technologies VT6122
> gigabit ethernet chip and integrated 10/100/1000 copper PHY.
> 
> Obtained from: FreeBSD

Is this tested on big endian machines?
Some FreeBSD guy always uses strange byteswap ops on reading
values from 93Cx6 based EEPROM, which returns 16bit words.
(attached patch is not tested)
---
Izumi Tsutsui
tsutsui@ceres.dti.ne.jp


Index: sys/dev/pci/if_vge.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_vge.c,v
retrieving revision 1.1
diff -u -r1.1 if_vge.c
--- sys/dev/pci/if_vge.c	20 Feb 2005 18:34:33 -0000	1.1
+++ sys/dev/pci/if_vge.c	5 Mar 2005 11:24:53 -0000
@@ -147,8 +147,7 @@
 static int vge_ifmedia_upd	(struct ifnet *);
 static void vge_ifmedia_sts	(struct ifnet *, struct ifmediareq *);
 
-static void vge_eeprom_getword	(struct vge_softc *, int, u_int16_t *);
-static void vge_read_eeprom	(struct vge_softc *, caddr_t, int, int, int);
+static uint16_t vge_read_eeprom	(struct vge_softc *, int);
 
 static void vge_miipoll_start	(struct vge_softc *);
 static void vge_miipoll_stop	(struct vge_softc *);
@@ -216,14 +215,11 @@
 /*
  * Read a word of data stored in the EEPROM at address 'addr.'
  */
-static void
-vge_eeprom_getword(sc, addr, dest)
-	struct vge_softc	*sc;
-	int			addr;
-	u_int16_t		*dest;
+static uint16_t
+vge_read_eeprom(struct vge_softc *sc, int addr)
 {
-	register int		i;
-	u_int16_t		word = 0;
+	int i;
+	uint16_t word = 0;
 
 	/*
 	 * Enter EEPROM embedded programming mode. In order to
@@ -247,8 +243,7 @@
 
 	if (i == VGE_TIMEOUT) {
 		printf("%s: EEPROM read timed out\n", sc->sc_dev.dv_xname);
-		*dest = 0;
-		return;
+		return 0;
 	}
 
 	/* Read the result */
@@ -258,33 +253,7 @@
 	CSR_CLRBIT_1(sc, VGE_EECSR, VGE_EECSR_EMBP/*|VGE_EECSR_ECS*/);
 	CSR_CLRBIT_1(sc, VGE_CHIPCFG2, VGE_CHIPCFG2_EELOAD);
 
-	*dest = word;
-
-	return;
-}
-
-/*
- * Read a sequence of words from the EEPROM.
- */
-static void
-vge_read_eeprom(sc, dest, off, cnt, swap)
-	struct vge_softc	*sc;
-	caddr_t			dest;
-	int			off;
-	int			cnt;
-	int			swap;
-{
-	int			i;
-	u_int16_t		word = 0, *ptr;
-
-	for (i = 0; i < cnt; i++) {
-		vge_eeprom_getword(sc, off + i, &word);
-		ptr = (u_int16_t *)(dest + (i * 2));
-		if (swap)
-			*ptr = ntohs(word);
-		else
-			*ptr = word;
-	}
+	return word;
 }
 
 static void
@@ -875,6 +844,7 @@
 	pci_chipset_tag_t pc = pa->pa_pc;
 	const char *intrstr;
 	pci_intr_handle_t ih;
+	uint16_t val;
 
 	aprint_normal(": VIA VT612X Gigabit Ethernet (rev. %#x)\n",
 		PCI_REVISION(pa->pa_class));
@@ -921,8 +891,15 @@
 	/*
 	 * Get station address from the EEPROM.
 	 */
-	vge_read_eeprom(sc, (caddr_t)eaddr, VGE_EE_EADDR, 3, 0);
-	bcopy(eaddr, (char *)&sc->vge_eaddr, ETHER_ADDR_LEN);
+	val = vge_read_eeprom(sc, VGE_EE_EADDR + 0);
+	eaddr[0] = val & 0xff;
+	eaddr[1] = val >> 8;
+	val = vge_read_eeprom(sc, VGE_EE_EADDR + 1);
+	eaddr[2] = val & 0xff;
+	eaddr[3] = val >> 8;
+	val = vge_read_eeprom(sc, VGE_EE_EADDR + 2);
+	eaddr[4] = val & 0xff;
+	eaddr[5] = val >> 8;
 
 	printf("%s: Ethernet address: %s\n", sc->sc_dev.dv_xname,
 	    ether_sprintf(eaddr));