From owner-FreeBSD-users-jp@jp.FreeBSD.org Tue Jul 29 15:00:17 2003
Received: (from daemon@localhost)
	by castle.jp.FreeBSD.org (8.11.6p2+3.4W/8.11.3) id h6T60Hg15735;
	Tue, 29 Jul 2003 15:00:17 +0900 (JST)
	(envelope-from owner-FreeBSD-users-jp@jp.FreeBSD.org)
Received: from mail02.idc.renesas.com (mail.renesas.com [202.234.163.13])
	by castle.jp.FreeBSD.org (8.11.6p2+3.4W/8.11.3) with ESMTP/inet id h6T60HT15730
	for <FreeBSD-users-jp@jp.freebsd.org>; Tue, 29 Jul 2003 15:00:17 +0900 (JST)
	(envelope-from shibagaki.takeshi@renesas.com)
Received: from mail02.idc.renesas.com ([127.0.0.1])
	by mail02.idc.renesas.com with ESMTP id h6T60B1O029036
	for <FreeBSD-users-jp@jp.freebsd.org>; Tue, 29 Jul 2003 15:00:11 +0900 (JST)
Received: from guardian01.idc.renesas.com ([172.20.8.132])
	by mail02.idc.renesas.com with ESMTP id h6T60AUO029033
	for <FreeBSD-users-jp@jp.freebsd.org>; Tue, 29 Jul 2003 15:00:10 +0900 (JST)
Received: (from root@localhost)
	by guardian01.idc.renesas.com with  id h6T60Aku002711
	for FreeBSD-users-jp@jp.freebsd.org; Tue, 29 Jul 2003 15:00:10 +0900 (JST)
Received: from unknown [172.20.8.73] by guardian01.idc.renesas.com with SMTP id RAA02710 ; Tue, 29 Jul 2003 15:00:10 +0900
Received: from mta05.idc.renesas.com (localhost [127.0.0.1])
	by mta05.idc.renesas.com with ESMTP id h6T609aV022249
	for <FreeBSD-users-jp@jp.freebsd.org>; Tue, 29 Jul 2003 15:00:09 +0900 (JST)
Received: from rnsmtp01.hoku_r.renesas.com ([10.145.246.51])
	by mta05.idc.renesas.com with ESMTP id h6T609C9022246
	for <FreeBSD-users-jp@jp.freebsd.org>; Tue, 29 Jul 2003 15:00:09 +0900 (JST)
Received: from localhost ([10.145.89.72])
	by rnsmtp01.hoku_r.renesas.com (8.9.3/3.7W) with ESMTP id PAA21061
	for <FreeBSD-users-jp@jp.freebsd.org>; Tue, 29 Jul 2003 15:00:09 +0900 (JST)
Message-Id: <20030729.150008.104026345.shibagaki.takeshi@renesas.com>
To: FreeBSD-users-jp@jp.FreeBSD.org
From: Takeshi Shibagaki <shibagaki.takeshi@renesas.com>
X-Mailer: Mew version 2.2 on Emacs 21.3 / Mule 5.0 (SAKAKI)
Mime-Version: 1.0
Content-Type: Multipart/Mixed;
 boundary="--Next_Part(Tue_Jul_29_15:00:08_2003_716)--"
Content-Transfer-Encoding: 7bit
Reply-To: FreeBSD-users-jp@jp.FreeBSD.org
Precedence: list
Date: Tue, 29 Jul 2003 15:00:08 +0900
X-Sequence: FreeBSD-users-jp 75532
Subject: [FreeBSD-users-jp 75532] -current =?ISO-2022-JP?B?GyRCJEcbKEI=?=
 =?ISO-2022-JP?B?GyRCJE4bKEI=?= ed,ep,fe
 =?ISO-2022-JP?B?GyRCJCIkPyRqJE5GMDpuGyhC?= 
Sender: owner-FreeBSD-users-jp@jp.FreeBSD.org
X-Originator: shibagaki.takeshi@renesas.com
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+030702

----Next_Part(Tue_Jul_29_15:00:08_2003_716)--
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit

$B<F3@$G$9!#(B

# $BEPO?30$N%"%I%l%9$+$i$G$9$,!#(B

hub($B2q<R(B) ----- AP ---- wi0 + FreeBSD + ed0 ---- WindowsNT

$B$H$$$&46$8$G!"(B-current$B%^%7%s$K(BNAT$B$r$d$i$;$F$$$k$N$G$9$,!"(Bgcc 3.3.1$B$,(B
import$B$5$l$?$"$?$j$+$i(B

ed0: remote transmit DMA failed to complete
ed: packets buffered, but transmitter idle

$B$J$I$H$$$&%m%0$r=P$9$h$&$K$J$C$F!"DL?.$,$D$^$k$h$&$J>uBV$K$J$C$F$7$^$$(B
$B$^$7$?!#C/$+$,D>$7$F$/$l$k$+$J$H;W$C$FBT$C$F$$$?$N$G$9$,!"D>$i$J$$$N$G!"(B
$B%/%$%C%/%O%C%/$G%m%C%/<~$j$N%3!<%I$r8+D>$7$F0l1~F0$/$h$&$K$7$F$_$^$7$?!#(B

$BB>$KF1$8$h$&$JLdBj$KEv$C$F$$$k?M$O$$$^$9$+(B?

ed, ep, fe$B$H$+F0:n$,$*$+$7$/$J$C$F$=$&$J$s$G$9$,!"$I$&$G$7$g$&$+!#(B

# $B:#;~$3$s$J8E$$$N$O;H$o$J$$$+$J$!!#(B

$B<F3@(B $B0R(B
shibagaki.takeshi@renesas.com

----Next_Part(Tue_Jul_29_15:00:08_2003_716)--
Content-Type: Multipart/Mixed;
 boundary="--BOUNDARY1(Tue_Jul_29_15:00:08_2003_233)--"
Content-Transfer-Encoding: 7bit

----BOUNDARY1(Tue_Jul_29_15:00:08_2003_233)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Description: diff1
Content-Disposition: inline; filename=diff1

--- if_ed.c.orig	Tue Jul 29 13:59:39 2003
+++ if_ed.c	Tue Jul 29 12:03:08 2003
@@ -76,8 +76,10 @@
 devclass_t ed_devclass;
 
 static void	ed_init		(void *);
+static void	ed_init_body	(struct ed_softc *sc);
 static int	ed_ioctl	(struct ifnet *, u_long, caddr_t);
 static void	ed_start	(struct ifnet *);
+static void	ed_start_body	(struct ifnet *);
 static void	ed_reset	(struct ifnet *);
 static void	ed_watchdog	(struct ifnet *);
 #ifndef ED_NO_MIIBUS
@@ -88,9 +90,9 @@
 
 static void	ed_get_packet	(struct ed_softc *, char *, /* u_short */ int);
 
-static __inline void	ed_rint	(struct ed_softc *);
-static __inline void	ed_xmit	(struct ed_softc *);
-static __inline char *	ed_ring_copy(struct ed_softc *, char *, char *,
+static void	ed_rint	(struct ed_softc *);
+static void	ed_xmit	(struct ed_softc *);
+static char *	ed_ring_copy(struct ed_softc *, char *, char *,
 					  /* u_short */ int);
 static void	ed_hpp_set_physical_link(struct ed_softc *);
 static void	ed_hpp_readmem	(struct ed_softc *, int, unsigned char *,
@@ -1559,6 +1561,12 @@
 {
 	struct ed_softc *sc = device_get_softc(dev);
 
+	mtx_assert(&sc->sc_mtx, MA_NOTOWNED);
+	if (sc->irq_handle)
+		panic("ed_release() called with intr handle still active");
+	if (sc->miibus)
+		device_delete_child(dev, sc->miibus);
+	bus_generic_detach(dev);
 	if (sc->port_res) {
 		bus_deactivate_resource(dev, SYS_RES_IOPORT,
 				     sc->port_rid, sc->port_res);
@@ -1580,6 +1588,8 @@
 				     sc->irq_rid, sc->irq_res);
 		sc->irq_res = 0;
 	}
+
+	mtx_destroy(&sc->sc_mtx);
 }
 
 /*
@@ -1592,8 +1602,12 @@
 	int flags;
 {
 	struct ifnet *ifp = &sc->arpcom.ac_if;
+	int s;
 
 	callout_handle_init(&sc->tick_ch);
+	mtx_init(&sc->sc_mtx, device_get_nameunit(sc->dev), MTX_NETWORK_LOCK,
+		MTX_DEF);
+	s = splimp();
 	/*
 	 * Set interface to stopped condition (reset)
 	 */
@@ -1667,6 +1681,8 @@
 			 (sc->vendor == ED_VENDOR_HP)) &&
 		(ifp->if_flags & IFF_ALTPHYS)) ? " tranceiver disabled" : "");
 
+	splx(s);
+
 	return (0);
 }
 
@@ -1678,19 +1694,14 @@
 	struct ifnet *ifp;
 {
 	struct ed_softc *sc = ifp->if_softc;
-	int     s;
 
 	if (sc->gone)
 		return;
-	s = splimp();
 
 	/*
 	 * Stop interface and re-initialize.
 	 */
-	ed_stop(sc);
-	ed_init(sc);
-
-	(void) splx(s);
+	ed_init_body(sc);
 }
 
 /*
@@ -1732,12 +1743,14 @@
 {
 	struct ed_softc *sc = ifp->if_softc;
 
+	ED_LOCK(sc);
 	if (sc->gone)
 		return;
 	log(LOG_ERR, "ed%d: device timeout\n", ifp->if_unit);
 	ifp->if_oerrors++;
 
 	ed_reset(ifp);
+	ED_UNLOCK(sc);
 }
 
 #ifndef ED_NO_MIIBUS
@@ -1749,28 +1762,39 @@
 	struct mii_data *mii;
 	int s;
 
+	ED_LOCK(sc);
+	s = splimp();
 	if (sc->gone) {
 		callout_handle_init(&sc->tick_ch);
 		return;
 	}
-	s = splimp();
 	if (sc->miibus != NULL) {
 		mii = device_get_softc(sc->miibus);
 		mii_tick(mii);
 	}
 	sc->tick_ch = timeout(ed_tick, sc, hz);
+	ED_UNLOCK(sc);
 	splx(s);
 }
 #endif
 
-/*
- * Initialize device.
- */
 static void
 ed_init(xsc)
 	void *xsc;
 {
 	struct ed_softc *sc = xsc;
+
+	ED_LOCK(sc);
+	ed_init_body(sc);
+	ED_UNLOCK(sc);
+}
+/*
+ * Initialize device.
+ */
+static void
+ed_init_body(sc)
+	struct ed_softc *sc;
+{
 	struct ifnet *ifp = &sc->arpcom.ac_if;
 	int     i, s;
 
@@ -1786,8 +1810,11 @@
 	 * This init procedure is "mandatory"...don't change what or when
 	 * things happen.
 	 */
+	mtx_assert(&sc->sc_mtx, MA_OWNED);
 	s = splimp();
 
+	ed_stop(sc);
+
 	/* reset transmitter flags */
 	sc->xmit_busy = 0;
 	ifp->if_timer = 0;
@@ -1920,7 +1947,7 @@
 	/*
 	 * ...and attempt to start output
 	 */
-	ed_start(ifp);
+	ed_start_body(ifp);
 
 #ifndef ED_NO_MIIBUS
 	untimeout(ed_tick, sc, sc->tick_ch);
@@ -1932,7 +1959,7 @@
 /*
  * This routine actually starts the transmission on the interface
  */
-static __inline void
+static void
 ed_xmit(sc)
 	struct ed_softc *sc;
 {
@@ -1979,6 +2006,16 @@
 	ifp->if_timer = 2;
 }
 
+static void
+ed_start(ifp)
+	struct ifnet *ifp;
+{
+	struct ed_softc *sc = ifp->if_softc;
+
+	ED_LOCK(sc);
+	ed_start_body(ifp);
+	ED_UNLOCK(sc);
+}
 /*
  * Start output on interface.
  * We make two assumptions here:
@@ -1989,7 +2026,7 @@
  *     (i.e. that the output part of the interface is idle)
  */
 static void
-ed_start(ifp)
+ed_start_body(ifp)
 	struct ifnet *ifp;
 {
 	struct ed_softc *sc = ifp->if_softc;
@@ -1997,6 +2034,7 @@
 	caddr_t buffer;
 	int     len;
 
+	mtx_assert(&sc->sc_mtx, MA_OWNED);
 	if (sc->gone) {
 		printf("ed_start(%p) GONE\n",ifp);
 		return;
@@ -2140,7 +2178,7 @@
 /*
  * Ethernet interface receiver interrupt.
  */
-static __inline void
+static void
 ed_rint(sc)
 	struct ed_softc *sc;
 {
@@ -2280,12 +2318,15 @@
 	void *arg;
 {
 	struct ed_softc *sc = (struct ed_softc*) arg;
-	struct ifnet *ifp = (struct ifnet *)sc;
+	struct ifnet *ifp = &sc->sc_if;
 	u_char  isr;
 	int	count;
 
-	if (sc->gone)
+	ED_LOCK(sc);
+	if (sc->gone) {
+		ED_UNLOCK(sc);
 		return;
+	}
 	/*
 	 * Set NIC to page 0 registers
 	 */
@@ -2516,7 +2557,7 @@
 		 * after handling the receiver to give the receiver priority.
 		 */
 		if ((ifp->if_flags & IFF_OACTIVE) == 0)
-			ed_start(ifp);
+			ed_start_body(ifp);
 
 		/*
 		 * return NIC CR to standard state: page 0, remote DMA
@@ -2537,6 +2578,7 @@
 			(void) ed_nic_inb(sc, ED_P0_CNTR2);
 		}
 	}
+	ED_UNLOCK(sc);
 }
 
 /*
@@ -2560,6 +2602,10 @@
 		ifp->if_flags &= ~IFF_RUNNING;
 		return ENXIO;
 	}
+	if (mtx_owned(&sc->sc_mtx))
+		return (EBUSY);
+
+	ED_LOCK(sc);
 	s = splimp();
 
 	switch (command) {
@@ -2571,7 +2617,7 @@
 		 */
 		if (ifp->if_flags & IFF_UP) {
 			if ((ifp->if_flags & IFF_RUNNING) == 0)
-				ed_init(sc);
+				ed_init_body(sc);
 		} else {
 			if (ifp->if_flags & IFF_RUNNING) {
 				ed_stop(sc);
@@ -2622,8 +2668,12 @@
 #endif
 
 	default:
+		ED_UNLOCK(sc);
 		error = ether_ioctl(ifp, command, data);
 	}
+	if (mtx_owned(&sc->sc_mtx))
+		ED_UNLOCK(sc);
+
 	(void) splx(s);
 	return (error);
 }
@@ -2633,7 +2683,7 @@
  *	the ring buffer into a linear destination buffer. Takes into account
  *	ring-wrap.
  */
-static __inline char *
+static char *
 ed_ring_copy(sc, src, dst, amount)
 	struct ed_softc *sc;
 	char   *src;
@@ -2733,7 +2783,9 @@
 
 	m->m_pkthdr.len = m->m_len = len;
 
+	ED_UNLOCK(sc);
 	(*ifp->if_input)(ifp, m);
+	ED_LOCK(sc);
 }
 
 /*
--- if_ed_pccard.c.orig	Mon Jul 28 05:48:24 2003
+++ if_ed_pccard.c	Tue Jul 29 11:59:44 2003
@@ -101,16 +101,23 @@
 {
 	struct ed_softc *sc = device_get_softc(dev);
 	struct ifnet *ifp = &sc->arpcom.ac_if;
+	int s;
+
+	ED_LOCK(sc);
+	s = splimp();
 
 	if (sc->gone) {
 		device_printf(dev, "already unloaded\n");
 		return (0);
 	}
-	ed_stop(sc);
 	ifp->if_flags &= ~IFF_RUNNING;
 	ether_ifdetach(ifp);
+	ed_stop(sc);
+	ED_UNLOCK(sc);
 	sc->gone = 1;
 	bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
+	sc->irq_handle = NULL;
+	splx(s);
 	ed_release_resources(dev);
 	return (0);
 }
@@ -250,6 +257,8 @@
 	u_char sum;
 	u_char ether_addr[ETHER_ADDR_LEN];
 	
+	sc->dev = dev;
+
 	if (sc->port_used > 0)
 		ed_alloc_port(dev, sc->port_rid, sc->port_used);
 	if (sc->mem_used)
--- if_edvar.h.orig	Wed Mar 20 11:07:18 2002
+++ if_edvar.h	Tue Jul 29 11:52:08 2003
@@ -49,7 +49,9 @@
 	int	irq_rid;	/* resource id for irq */
 	struct resource* irq_res; /* resource for irq */
 	void*	irq_handle;	/* handle for irq handler */
+	struct mtx sc_mtx;
 	device_t miibus;	/* MII bus for cards with MII. */
+	device_t dev;
 	void	(*mii_writebits)(struct ed_softc *, u_int, int);
 	u_int	(*mii_readbits)(struct ed_softc *, int);
 	struct callout_handle tick_ch; /* Callout handle for ed_tick */
@@ -220,4 +222,20 @@
 driver_intr_t	edintr;
 
 extern devclass_t ed_devclass;
+
+#define sc_if			arpcom.ac_if
+
+#if __FreeBSD_version < 500000
+#define ED_LOCK(_sc)
+#define ED_UNLOCK(_sc)
+#define mtx_owned(a)		0
+#define mtx_assert(a, b)
+#define mtx_init(a, b, c, d)
+#define mtx_destroy(a)
+struct mtx { int dummy; };
+#else
+#define ED_LOCK(_sc)           mtx_lock(&(_sc)->sc_mtx)
+#define ED_UNLOCK(_sc)         mtx_unlock(&(_sc)->sc_mtx)
+#endif
+
 #endif /* SYS_DEV_ED_IF_EDVAR_H */

----BOUNDARY1(Tue_Jul_29_15:00:08_2003_233)----

----Next_Part(Tue_Jul_29_15:00:08_2003_716)----
