From owner-svn-src-user@FreeBSD.ORG Tue Feb 3 18:07:21 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A64791065672; Tue, 3 Feb 2009 18:07:21 +0000 (UTC) (envelope-from thompsa@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8B44C8FC0C; Tue, 3 Feb 2009 18:07:21 +0000 (UTC) (envelope-from thompsa@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n13I7LMF037412; Tue, 3 Feb 2009 18:07:21 GMT (envelope-from thompsa@svn.freebsd.org) Received: (from thompsa@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n13I7LeZ037410; Tue, 3 Feb 2009 18:07:21 GMT (envelope-from thompsa@svn.freebsd.org) Message-Id: <200902031807.n13I7LeZ037410@svn.freebsd.org> From: Andrew Thompson Date: Tue, 3 Feb 2009 18:07:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r188081 - user/thompsa/usb/sys/dev/usb2/ethernet X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Feb 2009 18:07:22 -0000 Author: thompsa Date: Tue Feb 3 18:07:21 2009 New Revision: 188081 URL: http://svn.freebsd.org/changeset/base/188081 Log: Use a flag and cv when initing the hardware as the device could be detached while the driver init is sleeping. Spotted by: HPS Modified: user/thompsa/usb/sys/dev/usb2/ethernet/usb2_ethernet.c user/thompsa/usb/sys/dev/usb2/ethernet/usb2_ethernet.h Modified: user/thompsa/usb/sys/dev/usb2/ethernet/usb2_ethernet.c ============================================================================== --- user/thompsa/usb/sys/dev/usb2/ethernet/usb2_ethernet.c Tue Feb 3 17:58:20 2009 (r188080) +++ user/thompsa/usb/sys/dev/usb2/ethernet/usb2_ethernet.c Tue Feb 3 18:07:21 2009 (r188081) @@ -27,6 +27,7 @@ #include #include #include +#include #include SYSCTL_NODE(_net, OID_AUTO, ue, CTLFLAG_RD, 0, "USB Ethernet parameters"); @@ -102,6 +103,7 @@ usb2_ether_ifattach(struct usb2_ether *u USB_TASK_INIT(&ue->ue_tick_task, ue_tick_task, ue, ue->ue_mtx); usb2_callout_init_mtx(&ue->ue_watchdog, ue->ue_mtx, 0); sysctl_ctx_init(&ue->ue_sysctl_ctx); + usb2_cv_init(&ue->ue_cv, device_get_nameunit(ue->ue_dev)); error = usb2_proc_create(&ue->ue_tq, USB_PRI_MED, device_get_nameunit(ue->ue_dev)); @@ -172,6 +174,12 @@ usb2_ether_ifdetach(struct usb2_ether *u KASSERT((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0, ("ifnet still running")); + UE_LOCK(ue); + /* Wait if the interface init routine is still running */ + while (ue->ue_flags & UE_FLAG_INIT) + usb2_cv_wait(&ue->ue_cv, ue->ue_mtx); + UE_UNLOCK(ue); + usb2_callout_drain(&ue->ue_watchdog); usb2_proc_free(&ue->ue_tq); if (ue->ue_miibus) @@ -179,6 +187,7 @@ usb2_ether_ifdetach(struct usb2_ether *u ether_ifdetach(ifp); if_free(ifp); sysctl_ctx_free(&ue->ue_sysctl_ctx); + usb2_cv_destroy(&ue->ue_cv); free_unr(ueunit, ue->ue_unit); } @@ -199,7 +208,15 @@ ue_init_locked(struct usb2_ether *ue) UE_LOCK_ASSERT(ue, MA_OWNED); + /* + * Init the hardware, this is flagged as the device could be + * detached while the driver init is sleeping. + */ + ue->ue_flags |= UE_FLAG_INIT; ue->ue_init(ue->ue_sc); + ue->ue_flags &= ~UE_FLAG_INIT; + usb2_cv_signal(&ue->ue_cv); + if ((ifp->if_drv_flags & IFF_DRV_RUNNING) && ue->ue_tick != NULL) usb2_callout_reset(&ue->ue_watchdog, hz, ue_watchdog, ue); } Modified: user/thompsa/usb/sys/dev/usb2/ethernet/usb2_ethernet.h ============================================================================== --- user/thompsa/usb/sys/dev/usb2/ethernet/usb2_ethernet.h Tue Feb 3 17:58:20 2009 (r188080) +++ user/thompsa/usb/sys/dev/usb2/ethernet/usb2_ethernet.h Tue Feb 3 18:07:21 2009 (r188081) @@ -63,6 +63,10 @@ struct usb2_ether { struct ifqueue ue_rxq; + int ue_flags; +#define UE_FLAG_INIT 1 + + struct cv ue_cv; struct usb2_callout ue_watchdog; struct usb2_task ue_media_task; struct usb2_task ue_multi_task;