Mon Jan 10 13:29:29 2011 UTC ()
Use ether_aton_r() in sys/net/if_ethersubr.c instead of home grown copies.
Hint from ryo@.  Tested on IP32 mec(4).


(tsutsui)
diff -r1.36 -r1.37 src/sys/arch/sgimips/hpc/if_sq.c
diff -r1.2 -r1.3 src/sys/arch/sgimips/ioc/if_le_oioc.c
diff -r1.43 -r1.44 src/sys/arch/sgimips/mace/if_mec.c

cvs diff -r1.36 -r1.37 src/sys/arch/sgimips/hpc/if_sq.c (expand / switch to context diff)
--- src/sys/arch/sgimips/hpc/if_sq.c 2010/04/05 07:19:31 1.36
+++ src/sys/arch/sgimips/hpc/if_sq.c 2011/01/10 13:29:29 1.37
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_sq.c,v 1.36 2010/04/05 07:19:31 joerg Exp $	*/
+/*	$NetBSD: if_sq.c,v 1.37 2011/01/10 13:29:29 tsutsui Exp $	*/
 
 /*
  * Copyright (c) 2001 Rafal K. Boni
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_sq.c,v 1.36 2010/04/05 07:19:31 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_sq.c,v 1.37 2011/01/10 13:29:29 tsutsui Exp $");
 
 
 #include <sys/param.h>
@@ -118,8 +118,6 @@
 static void 	sq_dump_buffer(paddr_t addr, psize_t len);
 static void	sq_trace_dump(struct sq_softc *);
 
-static void	enaddr_aton(const char*, u_int8_t*);
-
 CFATTACH_DECL(sq, sizeof(struct sq_softc),
     sq_match, sq_attach, NULL, NULL);
 
@@ -282,7 +280,7 @@
 			printf(": unable to get MAC address!\n");
 			goto fail_6;
 		}
-		enaddr_aton(macaddr, sc->sc_enaddr);
+		ether_aton_r(sc->sc_enaddr, sizeof(sc->sc_enaddr), macaddr);
 	}
 
 	evcnt_attach_dynamic(&sc->sq_intrcnt, EVCNT_TYPE_INTR, NULL,
@@ -1331,30 +1329,4 @@
 	}
 
 	printf("\n");
-}
-
-void
-enaddr_aton(const char* str, u_int8_t* eaddr)
-{
-	int i;
-	char c;
-
-	for (i = 0; i < ETHER_ADDR_LEN; i++) {
-		if (*str == ':')
-			str++;
-
-		c = *str++;
-		if (isdigit(c)) {
-			eaddr[i] = (c - '0');
-		} else if (isxdigit(c)) {
-			eaddr[i] = (toupper(c) + 10 - 'A');
-		}
-
-		c = *str++;
-		if (isdigit(c)) {
-			eaddr[i] = (eaddr[i] << 4) | (c - '0');
-		} else if (isxdigit(c)) {
-			eaddr[i] = (eaddr[i] << 4) | (toupper(c) + 10 - 'A');
-		}
-	}
 }

cvs diff -r1.2 -r1.3 src/sys/arch/sgimips/ioc/if_le_oioc.c (expand / switch to context diff)
--- src/sys/arch/sgimips/ioc/if_le_oioc.c 2010/01/19 22:06:22 1.2
+++ src/sys/arch/sgimips/ioc/if_le_oioc.c 2011/01/10 13:29:29 1.3
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_le_oioc.c,v 1.2 2010/01/19 22:06:22 pooka Exp $	*/
+/*	$NetBSD: if_le_oioc.c,v 1.3 2011/01/10 13:29:29 tsutsui Exp $	*/
 
 /*
  * Copyright (c) 2009 Stephen M. Rumble
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_le_oioc.c,v 1.2 2010/01/19 22:06:22 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_le_oioc.c,v 1.3 2011/01/10 13:29:29 tsutsui Exp $");
 
 #include "opt_inet.h"
 
@@ -113,7 +113,6 @@
 
 static void	lewrcsr(struct lance_softc *, uint16_t, uint16_t);
 static uint16_t	lerdcsr(struct lance_softc *, uint16_t);  
-static void	enaddr_aton(const char *, u_int8_t *);
 
 static void
 lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
@@ -158,7 +157,7 @@
 	struct oioc_attach_args *oa = aux;
 	struct pglist mlist;
 	const char *enaddrstr;
-	char enaddr[6];
+	char enaddr[ETHER_ADDR_LEN];
 	char pbuf[9];
 	int i, error;
 
@@ -211,7 +210,7 @@
 	sc->sc_addr = 0;
 	sc->sc_conf3 = LE_C3_BSWP;
 
-	enaddr_aton(enaddrstr, enaddr);
+	ether_aton_r(enaddr, sizeof(enaddr), enaddrstr);
 	memcpy(sc->sc_enaddr, enaddr, sizeof(sc->sc_enaddr));
 
 	if (cpu_intr_establish(oa->oa_irq, IPL_NET, am7990_intr, sc) == NULL) {
@@ -247,31 +246,4 @@
 	bus_space_unmap(oa->oa_st, oa->oa_sh, lesc->sc_rdph);
 fail_0:
 	return;
-}
-
-/* stolen from sgimips/hpc/if_sq.c */
-static void
-enaddr_aton(const char *str, u_int8_t *eaddr)
-{
-	int i;
-	char c;
-
-	for (i = 0; i < ETHER_ADDR_LEN; i++) {
-		if (*str == ':')
-			str++;
-
-		c = *str++;
-		if (isdigit(c)) {
-			eaddr[i] = (c - '0');
-		} else if (isxdigit(c)) {
-			eaddr[i] = (toupper(c) + 10 - 'A');
-		}
-
-		c = *str++;
-		if (isdigit(c)) {
-			eaddr[i] = (eaddr[i] << 4) | (c - '0');
-		} else if (isxdigit(c)) {
-			eaddr[i] = (eaddr[i] << 4) | (toupper(c) + 10 - 'A');
-		}
-	}
 }

cvs diff -r1.43 -r1.44 src/sys/arch/sgimips/mace/if_mec.c (expand / switch to context diff)
--- src/sys/arch/sgimips/mace/if_mec.c 2010/04/05 07:19:32 1.43
+++ src/sys/arch/sgimips/mace/if_mec.c 2011/01/10 13:29:29 1.44
@@ -1,4 +1,4 @@
-/* $NetBSD: if_mec.c,v 1.43 2010/04/05 07:19:32 joerg Exp $ */
+/* $NetBSD: if_mec.c,v 1.44 2011/01/10 13:29:29 tsutsui Exp $ */
 
 /*-
  * Copyright (c) 2004, 2008 Izumi Tsutsui.  All rights reserved.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_mec.c,v 1.43 2010/04/05 07:19:32 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mec.c,v 1.44 2011/01/10 13:29:29 tsutsui Exp $");
 
 #include "opt_ddb.h"
 #include "rnd.h"
@@ -397,8 +397,6 @@
 static int	mec_mii_wait(struct mec_softc *);
 static void	mec_statchg(device_t);
 
-static void	enaddr_aton(const char *, uint8_t *);
-
 static int	mec_init(struct ifnet * ifp);
 static void	mec_start(struct ifnet *);
 static void	mec_watchdog(struct ifnet *);
@@ -551,7 +549,7 @@
 		memcpy(sc->sc_enaddr+3, ((uint8_t *)&ui)+1, 3);
 	}
 	if (!mac_is_fake)
-		enaddr_aton(macaddr, sc->sc_enaddr);
+		ether_aton_r(sc->sc_enaddr, sizeof(sc->sc_enaddr), macaddr);
 
 	/* set the Ethernet address */
 	address = 0;
@@ -852,36 +850,6 @@
 	}
 
 	bus_space_write_8(st, sh, MEC_MAC_CONTROL, control);
-}
-
-/*
- * XXX
- * maybe this function should be moved to common part
- * (sgimips/machdep.c or elsewhere) for all on-board network devices.
- */
-static void
-enaddr_aton(const char *str, uint8_t *eaddr)
-{
-	int i;
-	char c;
-
-	for (i = 0; i < ETHER_ADDR_LEN; i++) {
-		if (*str == ':')
-			str++;
-
-		c = *str++;
-		if (isdigit(c)) {
-			eaddr[i] = (c - '0');
-		} else if (isxdigit(c)) {
-			eaddr[i] = (toupper(c) + 10 - 'A');
-		}
-		c = *str++;
-		if (isdigit(c)) {
-			eaddr[i] = (eaddr[i] << 4) | (c - '0');
-		} else if (isxdigit(c)) {
-			eaddr[i] = (eaddr[i] << 4) | (toupper(c) + 10 - 'A');
-		}
-	}
 }
 
 static int