From owner-freebsd-net@FreeBSD.ORG Fri Feb 16 23:41:39 2007 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 885EC16A400 for ; Fri, 16 Feb 2007 23:41:39 +0000 (UTC) (envelope-from doginou@dong.ci0.org) Received: from dong.ci0.org (cognet.ci0.org [80.65.224.102]) by mx1.freebsd.org (Postfix) with ESMTP id 47A4913C441 for ; Fri, 16 Feb 2007 23:41:38 +0000 (UTC) (envelope-from doginou@dong.ci0.org) Received: from dong.ci0.org (localhost.ci0.org [127.0.0.1]) by dong.ci0.org (8.13.7/8.13.4) with ESMTP id l1GNNuSw083575; Sat, 17 Feb 2007 00:23:56 +0100 (CET) (envelope-from doginou@dong.ci0.org) Received: (from doginou@localhost) by dong.ci0.org (8.13.8/8.13.8/Submit) id l1GNNtZ8083574; Sat, 17 Feb 2007 00:23:55 +0100 (CET) (envelope-from doginou) Date: Sat, 17 Feb 2007 00:23:55 +0100 From: Olivier Houchard To: "V.Chukharev" Message-ID: <20070216232355.GA83548@ci0.org> References: <20070216174317.GZ64768@obiwan.tataz.chchile.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="r5Pyd7+fXNt84Ff3" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i Cc: freebsd-net@freebsd.org, Jeremie Le Hen Subject: Re: iwi leaks memory? X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Feb 2007 23:41:39 -0000 --r5Pyd7+fXNt84Ff3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Feb 16, 2007 at 11:10:24PM +0200, V.Chukharev wrote: > On Fri, 16 Feb 2007 19:43:17 +0200, Jeremie Le Hen wrote: > > > Hi, > > > > cognet@ has once provided me a tiny hack to the iwi(4) driver and > > I never get such errors. Maybe I'm not suffering enough UP/DOWN > > cycles to trigger it, but it might be worth trying it. > > > > Note that he has insisted that this is a *hack*. > > > > The patch is attached. Please let us know if it makes things > > better. > > I cannot apply the patch ;-( > It seems it's for CURRENT, and I run STABLE. > Hi, I regenerated the patch against STABLE. Beware however, I didn't test it, only compile-test it, as I have no such hardware. Cheers, Olivier --r5Pyd7+fXNt84Ff3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="if_iwi.stable.diff" Index: dev/iwi/if_iwi.c =================================================================== RCS file: /cognet/ncvs/src/sys/dev/iwi/if_iwi.c,v retrieving revision 1.8.2.12 diff -u -p -r1.8.2.12 if_iwi.c --- dev/iwi/if_iwi.c 23 Jan 2007 22:17:48 -0000 1.8.2.12 +++ dev/iwi/if_iwi.c 16 Feb 2007 22:53:39 -0000 @@ -511,6 +511,12 @@ iwi_detach(device_t dev) if (sc->mem != NULL) bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem); + if (sc->fw_map) + bus_dmamap_unload(sc->fw_dmat, sc->fw_map); + if (sc->fw_virtaddr != 0) + bus_dmamem_free(sc->fw_dmat, sc->fw_virtaddr, sc->fw_map); + if (sc->fw_dmat) + bus_dma_tag_destroy(sc->fw_dmat); if (ifp != NULL) if_free(ifp); @@ -3079,6 +3085,7 @@ iwi_init_locked(void *priv, int force) struct ifnet *ifp = ic->ic_ifp; struct iwi_rx_data *data; int i; + int must_realloc = 0; IWI_LOCK_DECL; if (sc->flags & IWI_FLAG_FW_LOADING) @@ -3100,14 +3107,26 @@ iwi_init_locked(void *priv, int force) } /* allocate DMA memory for mapping firmware image */ - if (sc->fw_boot.size > sc->fw_dma_size) + if (sc->fw_boot.size > sc->fw_dma_size) { + must_realloc = 1; sc->fw_dma_size = sc->fw_boot.size; - if (sc->fw_fw.size > sc->fw_dma_size) + } + if (sc->fw_fw.size > sc->fw_dma_size) { + must_realloc = 1; sc->fw_dma_size = sc->fw_fw.size; - if (sc->fw_uc.size > sc->fw_dma_size) + } + if (sc->fw_uc.size > sc->fw_dma_size) { + must_realloc = 1; sc->fw_dma_size = sc->fw_uc.size; - - if (bus_dma_tag_create(NULL, 4, 0, BUS_SPACE_MAXADDR_32BIT, + } + if (must_realloc && sc->fw_virtaddr != 0) { + bus_dmamap_sync(sc->fw_dmat, sc->fw_map, BUS_DMASYNC_POSTWRITE); + bus_dmamap_unload(sc->fw_dmat, sc->fw_map); + bus_dmamem_free(sc->fw_dmat, sc->fw_virtaddr, sc->fw_map); + bus_dma_tag_destroy(sc->fw_dmat); + } + if (must_realloc && + bus_dma_tag_create(NULL, 4, 0, BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, sc->fw_dma_size, 1, sc->fw_dma_size, 0, NULL, NULL, &sc->fw_dmat) != 0) { device_printf(sc->sc_dev, @@ -3115,14 +3134,16 @@ iwi_init_locked(void *priv, int force) IWI_LOCK(sc); goto fail; } - if (bus_dmamem_alloc(sc->fw_dmat, &sc->fw_virtaddr, 0, + if (must_realloc && + bus_dmamem_alloc(sc->fw_dmat, &sc->fw_virtaddr, 0, &sc->fw_map) != 0) { device_printf(sc->sc_dev, "could not allocate firmware DMA memory\n"); IWI_LOCK(sc); goto fail2; } - if (bus_dmamap_load(sc->fw_dmat, sc->fw_map, sc->fw_virtaddr, + if (must_realloc && + bus_dmamap_load(sc->fw_dmat, sc->fw_map, sc->fw_virtaddr, sc->fw_dma_size, iwi_dma_map_addr, &sc->fw_physaddr, 0) != 0) { device_printf(sc->sc_dev, "could not load firmware DMA map\n"); IWI_LOCK(sc); @@ -3178,11 +3199,6 @@ iwi_init_locked(void *priv, int force) } sc->flags |= IWI_FLAG_FW_INITED; - bus_dmamap_sync(sc->fw_dmat, sc->fw_map, BUS_DMASYNC_POSTWRITE); - bus_dmamap_unload(sc->fw_dmat, sc->fw_map); - bus_dmamem_free(sc->fw_dmat, sc->fw_virtaddr, sc->fw_map); - bus_dma_tag_destroy(sc->fw_dmat); - if (iwi_config(sc) != 0) { device_printf(sc->sc_dev, "device configuration failed\n"); goto fail; @@ -3211,6 +3227,7 @@ fail4: bus_dmamap_sync(sc->fw_dmat, sc-> fail3: bus_dmamem_free(sc->fw_dmat, sc->fw_virtaddr, sc->fw_map); fail2: bus_dma_tag_destroy(sc->fw_dmat); fail: ifp->if_flags &= ~IFF_UP; + sc->fw_virtaddr = 0; sc->flags &= ~IWI_FLAG_FW_LOADING; iwi_stop(sc); iwi_put_firmware(sc); --r5Pyd7+fXNt84Ff3--