From owner-freebsd-hackers@FreeBSD.ORG Mon Nov 21 16:31:45 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 45A1E16A41F for ; Mon, 21 Nov 2005 16:31:45 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from speedfactory.net (mail6.speedfactory.net [66.23.216.219]) by mx1.FreeBSD.org (Postfix) with ESMTP id BE6BB43D53 for ; Mon, 21 Nov 2005 16:31:44 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (unverified [66.23.211.162]) by speedfactory.net (SurgeMail 3.5b3) with ESMTP id 2367511 for multiple; Mon, 21 Nov 2005 11:31:54 -0500 Received: from localhost (john@localhost [127.0.0.1]) by server.baldwin.cx (8.13.1/8.13.1) with ESMTP id jALGVdYg069777; Mon, 21 Nov 2005 11:31:39 -0500 (EST) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Mon, 21 Nov 2005 10:36:07 -0500 User-Agent: KMail/1.8.2 References: <9f9993160511200804w177a521s9cddc6e56afe221e@mail.gmail.com> In-Reply-To: <9f9993160511200804w177a521s9cddc6e56afe221e@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200511211036.08460.jhb@freebsd.org> X-Spam-Status: No, score=-2.8 required=4.2 tests=ALL_TRUSTED autolearn=failed version=3.0.2 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on server.baldwin.cx X-Server: High Performance Mail Server - http://surgemail.com r=1653887525 Cc: rashmi ns , bugi@lists.redbrick.dcu.ie Subject: Re: Driver crashes after unloading a module X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Nov 2005 16:31:45 -0000 On Sunday 20 November 2005 11:04 am, rashmi ns wrote: > Hello List , > > Thanks for the help you given me . > > We have written driver for hdlc controller .The kernel is crashing > after unloading > the module with trap 12 fault .here is the order in which we release the > resources while detaching the device. > > 1. stop polling timer(if polling mode) > > 2. destroy_dev() > > 3. disable the device > > 4. free Tx and Rx structures > > 5. deallocate allocated dma memory > > 6. bus_deactivate_resource(irq) > > 7. release all bus resources > > here is the piece of code > > /*release bus resources*/ > > static void hdlc_release(struct hdlc_softc *sc) > > { > > dbgprint("Entering"); > > bus_generic_detach(sc->dev); > > /*Release the resources held*/ > > if (sc->irq){ > > bus_teardown_intr(sc->dev, sc->irq,sc->int_handler_tag); > > sc->int_handler_tag = NULL; > > bus_release_resource(sc->dev, SYS_RES_IRQ,sc->irq_rid, sc->irq); > > dbgprint("deallocated irq res irq_rid = %d\n",sc->irq_rid); > > } > > if (sc->mem){ > > bus_release_resource (sc->dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem); > > dbgprint("deallocated bus res\n"); > > } > > if(&sc->sc_mtx) > > mtx_destroy(&sc->sc_mtx); > > } As a first guess, do this later since you might still get an open request up until your call to destroy_dev(). Also, you might need to create a purge routine your devsw if threads can block in your devsw routines and wakeup any sleepers in your purge handler so that when destroy-dev() returns you know that all threads are out of your driver. > /*detach function*/ > > static int hdlc_detach(device_t dev) > > { > > struct hdlc_softc *sc = device_get_softc(dev); > > int s; > > dbgprint("Entering\n"); > > s=splimp(); > > /*If drv is in poll mode then stop the poll timer */ > > if(sc->intr_mode == 0) > > hdlc_clear_poll_mode(sc); > > if(!(sc->hdlc_cdev == NULL) ){ > > destroy_dev(sc->hdlc_cdev); > > } > > /*stop the controller */ > > hdlc_hw_reset(sc); > > /*free hdlc Tx and Rx structures */ > > hdlc_stop(sc); > > /*deallocate allocated dma memory*/ > > hdlc_free_descriptors(sc); > > bus_deactivate_resource(sc->dev,SYS_RES_IRQ,sc->irq_rid,sc->irq); > > splx(s); > > /*free bus resources*/ > > hdlc_release(sc); > > uprintf("Detached\n"); > > return 0; > > } > > After unloading the module the it gives the debug print "Module > unloaded" kld_loader function from and kernel crashes with trap 12 .Kindly > let me know does the order of releasing the resources is the reason for > this. > > Thanks and regards, > > Rashmi.n.s > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org