Re: Add suspend/resume support for the bfe driver

From: John Baldwin <john_at_baldwin.cx>
Date: Fri, 17 Nov 2006 14:12:34 -0500
On Friday 17 November 2006 12:21, Stepan Zastupov wrote:
> A couple of weeks ago I wrote patch which added suspend/resume support
> for the bfe driver. It just attach/deattach device when suspend/resume
> as it done in Linux driver. In pr I wrote that it dosen'y help but now I
> know that it dose! Just need to stop devd before suspend, I do it from
> the /etc/rc.suspend and start from /etc/rc.resume. I hope somebody
> commit the patch into kernel tree.
> Here is the pr http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/104652

Usually drivers don't detach on suspend.  How about this patch instead:

Index: if_bfe.c
===================================================================
RCS file: /usr/cvs/src/sys/dev/bfe/if_bfe.c,v
retrieving revision 1.40
diff -u -r1.40 if_bfe.c
--- if_bfe.c	28 May 2006 20:35:39 -0000	1.40
+++ if_bfe.c	17 Nov 2006 19:11:47 -0000
_at__at_ -87,6 +87,8 _at__at_
 static int  bfe_probe				(device_t);
 static int  bfe_attach				(device_t);
 static int  bfe_detach				(device_t);
+static int  bfe_suspend				(device_t);
+static int  bfe_resume				(device_t);
 static void bfe_release_resources	(struct bfe_softc *);
 static void bfe_intr				(void *);
 static void bfe_start				(struct ifnet *);
_at__at_ -136,6 +138,8 _at__at_
 	DEVMETHOD(device_attach,	bfe_attach),
 	DEVMETHOD(device_detach,	bfe_detach),
 	DEVMETHOD(device_shutdown,	bfe_shutdown),
+	DEVMETHOD(device_suspend,	bfe_suspend),
+	DEVMETHOD(device_resume,	bfe_resume),
 
 	/* bus interface */
 	DEVMETHOD(bus_print_child,	bus_generic_print_child),
_at__at_ -480,6 +484,39 _at__at_
 }
 
 static int
+bfe_suspend(device_t dev)
+{
+	struct bfe_softc *sc;
+
+	sc = device_get_softc(dev);
+	BFE_LOCK(sc);
+	bfe_stop(sc);
+	BFE_UNLOCK(sc);
+
+	return (0);
+}
+
+static int
+bfe_resume(device_t dev)
+{
+	struct bfe_softc *sc;
+	struct ifnet *ifp;
+
+	sc = device_get_softc(dev);
+	ifp = sc->bfe_ifp;
+	BFE_LOCK(sc);
+	if (ifp->if_flags & IFF_UP) {
+		bfe_init_locked(sc);
+		if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
+		    !IFQ_DRV_IS_EMPTY(&ifp->if_snd))
+			bfe_start_locked(ifp);
+	}
+	BFE_UNLOCK(sc);
+
+	return (0);
+}
+
+static int
 bfe_miibus_readreg(device_t dev, int phy, int reg)
 {
 	struct bfe_softc *sc;

-- 
John Baldwin
Received on Fri Nov 17 2006 - 18:12:57 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:02 UTC