Sun Jan 9 00:12:45 2011 UTC ()
Try reading MAC addr from register if it fails to read from EEPROM.
Copied from FreeBSD driver.

Without this my JMC261 doesn't get MAC address properly.

OK'ed by bouyer@


(kochi)
diff -r1.15 -r1.16 src/sys/dev/pci/if_jme.c

cvs diff -r1.15 -r1.16 src/sys/dev/pci/if_jme.c (expand / switch to unified diff)

--- src/sys/dev/pci/if_jme.c 2010/11/13 13:52:06 1.15
+++ src/sys/dev/pci/if_jme.c 2011/01/09 00:12:45 1.16
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_jme.c,v 1.15 2010/11/13 13:52:06 uebayasi Exp $ */ 1/* $NetBSD: if_jme.c,v 1.16 2011/01/09 00:12:45 kochi Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008 Manuel Bouyer. All rights reserved. 4 * Copyright (c) 2008 Manuel Bouyer. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -48,27 +48,27 @@ @@ -48,27 +48,27 @@
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 */ 52 */
53 53
54 54
55/* 55/*
56 * Driver for JMicron Technologies JMC250 (Giganbit) and JMC260 (Fast) 56 * Driver for JMicron Technologies JMC250 (Giganbit) and JMC260 (Fast)
57 * Ethernet Controllers. 57 * Ethernet Controllers.
58 */ 58 */
59 59
60#include <sys/cdefs.h> 60#include <sys/cdefs.h>
61__KERNEL_RCSID(0, "$NetBSD: if_jme.c,v 1.15 2010/11/13 13:52:06 uebayasi Exp $"); 61__KERNEL_RCSID(0, "$NetBSD: if_jme.c,v 1.16 2011/01/09 00:12:45 kochi Exp $");
62 62
63 63
64#include <sys/param.h> 64#include <sys/param.h>
65#include <sys/systm.h> 65#include <sys/systm.h>
66#include <sys/mbuf.h> 66#include <sys/mbuf.h>
67#include <sys/protosw.h> 67#include <sys/protosw.h>
68#include <sys/socket.h> 68#include <sys/socket.h>
69#include <sys/ioctl.h> 69#include <sys/ioctl.h>
70#include <sys/errno.h> 70#include <sys/errno.h>
71#include <sys/malloc.h> 71#include <sys/malloc.h>
72#include <sys/kernel.h> 72#include <sys/kernel.h>
73#include <sys/proc.h> /* only for declaration of wakeup() used by vm.h */ 73#include <sys/proc.h> /* only for declaration of wakeup() used by vm.h */
74#include <sys/device.h> 74#include <sys/device.h>
@@ -205,26 +205,27 @@ static int jme_ifinit(struct ifnet *); @@ -205,26 +205,27 @@ static int jme_ifinit(struct ifnet *);
205static int jme_init(struct ifnet *, int); 205static int jme_init(struct ifnet *, int);
206static void jme_stop(struct ifnet *, int); 206static void jme_stop(struct ifnet *, int);
207// static void jme_restart(void *); 207// static void jme_restart(void *);
208static void jme_ticks(void *); 208static void jme_ticks(void *);
209static void jme_mac_config(jme_softc_t *); 209static void jme_mac_config(jme_softc_t *);
210static void jme_set_filter(jme_softc_t *); 210static void jme_set_filter(jme_softc_t *);
211 211
212int jme_mii_read(device_t, int, int); 212int jme_mii_read(device_t, int, int);
213void jme_mii_write(device_t, int, int, int); 213void jme_mii_write(device_t, int, int, int);
214void jme_statchg(device_t); 214void jme_statchg(device_t);
215 215
216static int jme_eeprom_read_byte(struct jme_softc *, uint8_t, uint8_t *); 216static int jme_eeprom_read_byte(struct jme_softc *, uint8_t, uint8_t *);
217static int jme_eeprom_macaddr(struct jme_softc *); 217static int jme_eeprom_macaddr(struct jme_softc *);
 218static int jme_reg_macaddr(struct jme_softc *);
218 219
219#define JME_TIMEOUT 1000 220#define JME_TIMEOUT 1000
220#define JME_PHY_TIMEOUT 1000 221#define JME_PHY_TIMEOUT 1000
221#define JME_EEPROM_TIMEOUT 1000 222#define JME_EEPROM_TIMEOUT 1000
222 223
223static int jme_sysctl_intrxto(SYSCTLFN_PROTO); 224static int jme_sysctl_intrxto(SYSCTLFN_PROTO);
224static int jme_sysctl_intrxct(SYSCTLFN_PROTO); 225static int jme_sysctl_intrxct(SYSCTLFN_PROTO);
225static int jme_sysctl_inttxto(SYSCTLFN_PROTO); 226static int jme_sysctl_inttxto(SYSCTLFN_PROTO);
226static int jme_sysctl_inttxct(SYSCTLFN_PROTO); 227static int jme_sysctl_inttxct(SYSCTLFN_PROTO);
227static int jme_root_num; 228static int jme_root_num;
228 229
229 230
230CFATTACH_DECL_NEW(jme, sizeof(jme_softc_t), 231CFATTACH_DECL_NEW(jme, sizeof(jme_softc_t),
@@ -374,27 +375,27 @@ jme_pci_attach(device_t parent, device_t @@ -374,27 +375,27 @@ jme_pci_attach(device_t parent, device_t
374 * requires PHY probing to get correct PHY address. 375 * requires PHY probing to get correct PHY address.
375 */ 376 */
376 if ((sc->jme_flags & JME_FLAG_FPGA) == 0) { 377 if ((sc->jme_flags & JME_FLAG_FPGA) == 0) {
377 sc->jme_phyaddr = 378 sc->jme_phyaddr =
378 bus_space_read_4(sc->jme_bt_misc, sc->jme_bh_misc, 379 bus_space_read_4(sc->jme_bt_misc, sc->jme_bh_misc,
379 JME_GPREG0) & GPREG0_PHY_ADDR_MASK; 380 JME_GPREG0) & GPREG0_PHY_ADDR_MASK;
380 } else 381 } else
381 sc->jme_phyaddr = 0; 382 sc->jme_phyaddr = 0;
382 383
383 384
384 jme_reset(sc); 385 jme_reset(sc);
385 386
386 /* read mac addr */ 387 /* read mac addr */
387 if (jme_eeprom_macaddr(sc)) { 388 if (jme_eeprom_macaddr(sc) && jme_reg_macaddr(sc)) {
388 aprint_error_dev(self, "error reading Ethernet address\n"); 389 aprint_error_dev(self, "error reading Ethernet address\n");
389 /* return; */ 390 /* return; */
390 } 391 }
391 aprint_normal_dev(self, "Ethernet address %s\n", 392 aprint_normal_dev(self, "Ethernet address %s\n",
392 ether_sprintf(sc->jme_enaddr)); 393 ether_sprintf(sc->jme_enaddr));
393 394
394 /* Map and establish interrupts */ 395 /* Map and establish interrupts */
395 if (pci_intr_map(pa, &intrhandle)) { 396 if (pci_intr_map(pa, &intrhandle)) {
396 aprint_error_dev(self, "couldn't map interrupt\n"); 397 aprint_error_dev(self, "couldn't map interrupt\n");
397 return; 398 return;
398 } 399 }
399 intrstr = pci_intr_string(pa->pa_pc, intrhandle); 400 intrstr = pci_intr_string(pa->pa_pc, intrhandle);
400 sc->jme_if.if_softc = sc; 401 sc->jme_if.if_softc = sc;
@@ -1990,26 +1991,48 @@ jme_eeprom_macaddr(struct jme_softc *sc) @@ -1990,26 +1991,48 @@ jme_eeprom_macaddr(struct jme_softc *sc)
1990  1991
1991 /* Try next eeprom descriptor. */ 1992 /* Try next eeprom descriptor. */
1992 offset += JME_EEPROM_DESC_BYTES; 1993 offset += JME_EEPROM_DESC_BYTES;
1993 } while (match != ETHER_ADDR_LEN && offset < JME_EEPROM_END); 1994 } while (match != ETHER_ADDR_LEN && offset < JME_EEPROM_END);
1994 1995
1995 if (match == ETHER_ADDR_LEN) { 1996 if (match == ETHER_ADDR_LEN) {
1996 memcpy(sc->jme_enaddr, eaddr, ETHER_ADDR_LEN); 1997 memcpy(sc->jme_enaddr, eaddr, ETHER_ADDR_LEN);
1997 return (0); 1998 return (0);
1998 } 1999 }
1999 2000
2000 return (ENOENT); 2001 return (ENOENT);
2001} 2002}
2002 2003
 2004static int
 2005jme_reg_macaddr(struct jme_softc *sc)
 2006{
 2007 uint32_t par0, par1;
 2008
 2009 par0 = bus_space_read_4(sc->jme_bt_mac, sc->jme_bh_mac, JME_PAR0);
 2010 par1 = bus_space_read_4(sc->jme_bt_mac, sc->jme_bh_mac, JME_PAR1);
 2011 par1 &= 0xffff;
 2012 if ((par0 == 0 && par1 == 0) ||
 2013 (par0 == 0xffffffff && par1 == 0xffff)) {
 2014 return (ENOENT);
 2015 } else {
 2016 sc->jme_enaddr[0] = (par0 >> 0) & 0xff;
 2017 sc->jme_enaddr[1] = (par0 >> 8) & 0xff;
 2018 sc->jme_enaddr[2] = (par0 >> 16) & 0xff;
 2019 sc->jme_enaddr[3] = (par0 >> 24) & 0xff;
 2020 sc->jme_enaddr[4] = (par1 >> 0) & 0xff;
 2021 sc->jme_enaddr[5] = (par1 >> 8) & 0xff;
 2022 }
 2023 return (0);
 2024}
 2025
2003/* 2026/*
2004 * Set up sysctl(3) MIB, hw.jme.* - Individual controllers will be 2027 * Set up sysctl(3) MIB, hw.jme.* - Individual controllers will be
2005 * set up in jme_pci_attach() 2028 * set up in jme_pci_attach()
2006 */ 2029 */
2007SYSCTL_SETUP(sysctl_jme, "sysctl jme subtree setup") 2030SYSCTL_SETUP(sysctl_jme, "sysctl jme subtree setup")
2008{ 2031{
2009 int rc; 2032 int rc;
2010 const struct sysctlnode *node; 2033 const struct sysctlnode *node;
2011 2034
2012 if ((rc = sysctl_createv(clog, 0, NULL, NULL, 2035 if ((rc = sysctl_createv(clog, 0, NULL, NULL,
2013 0, CTLTYPE_NODE, "hw", NULL, 2036 0, CTLTYPE_NODE, "hw", NULL,
2014 NULL, 0, NULL, 0, CTL_HW, CTL_EOL)) != 0) { 2037 NULL, 0, NULL, 0, CTL_HW, CTL_EOL)) != 0) {
2015 goto err; 2038 goto err;