From owner-svn-src-all@freebsd.org Fri May 20 11:02:05 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A70DCB43EA2; Fri, 20 May 2016 11:02:05 +0000 (UTC) (envelope-from wma@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6B3561338; Fri, 20 May 2016 11:02:05 +0000 (UTC) (envelope-from wma@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4KB24bf067761; Fri, 20 May 2016 11:02:04 GMT (envelope-from wma@FreeBSD.org) Received: (from wma@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4KB245w067759; Fri, 20 May 2016 11:02:04 GMT (envelope-from wma@FreeBSD.org) Message-Id: <201605201102.u4KB245w067759@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: wma set sender to wma@FreeBSD.org using -f From: Wojciech Macek Date: Fri, 20 May 2016 11:02:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300295 - head/sys/dev/vnic X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 May 2016 11:02:05 -0000 Author: wma Date: Fri May 20 11:02:04 2016 New Revision: 300295 URL: https://svnweb.freebsd.org/changeset/base/300295 Log: Fix VNIC module unloading Fix panics which were present when BGX and PF module were unloaded. Reviewed by: zbb Obtained from: Semihalf Sponsored by: Cavium Differential Revision: https://reviews.freebsd.org/D6346 Modified: head/sys/dev/vnic/nic_main.c head/sys/dev/vnic/thunder_bgx.c Modified: head/sys/dev/vnic/nic_main.c ============================================================================== --- head/sys/dev/vnic/nic_main.c Fri May 20 11:00:06 2016 (r300294) +++ head/sys/dev/vnic/nic_main.c Fri May 20 11:02:04 2016 (r300295) @@ -247,7 +247,9 @@ static int nicpf_detach(device_t dev) { struct nicpf *nic; + int err; + err = 0; nic = device_get_softc(dev); callout_drain(&nic->check_link); @@ -257,7 +259,12 @@ nicpf_detach(device_t dev) nicpf_free_res(nic); pci_disable_busmaster(dev); - return (0); +#ifdef PCI_IOV + err = pci_iov_detach(dev); + if (err != 0) + device_printf(dev, "SR-IOV in use. Detach first.\n"); +#endif + return (err); } /* @@ -1055,6 +1062,9 @@ nic_disable_msix(struct nicpf *nic) nic->msix_enabled = 0; nic->num_vec = 0; } + + bus_release_resource(nic->dev, SYS_RES_MEMORY, + rman_get_rid(nic->msix_table_res), nic->msix_table_res); } static void @@ -1071,7 +1081,7 @@ nic_free_all_interrupts(struct nicpf *ni nic->msix_entries[irq].handle); } - bus_release_resource(nic->dev, SYS_RES_IRQ, irq, + bus_release_resource(nic->dev, SYS_RES_IRQ, irq + 1, nic->msix_entries[irq].irq_res); } } Modified: head/sys/dev/vnic/thunder_bgx.c ============================================================================== --- head/sys/dev/vnic/thunder_bgx.c Fri May 20 11:00:06 2016 (r300294) +++ head/sys/dev/vnic/thunder_bgx.c Fri May 20 11:02:04 2016 (r300295) @@ -136,12 +136,16 @@ static int thunder_bgx_attach(device_t dev) { struct bgx *bgx; - uint8_t lmac; + uint8_t lmacid; int err; int rid; + struct lmac *lmac; bgx = malloc(sizeof(*bgx), M_BGX, (M_WAITOK | M_ZERO)); bgx->dev = dev; + + lmac = device_get_softc(dev); + lmac->bgx = bgx; /* Enable bus mastering */ pci_enable_busmaster(dev); /* Allocate resources - configuration registers */ @@ -168,11 +172,11 @@ thunder_bgx_attach(device_t dev) bgx_init_hw(bgx); /* Enable all LMACs */ - for (lmac = 0; lmac < bgx->lmac_count; lmac++) { - err = bgx_lmac_enable(bgx, lmac); + for (lmacid = 0; lmacid < bgx->lmac_count; lmacid++) { + err = bgx_lmac_enable(bgx, lmacid); if (err) { device_printf(dev, "BGX%d failed to enable lmac%d\n", - bgx->bgx_id, lmac); + bgx->bgx_id, lmacid); goto err_free_res; } } @@ -203,6 +207,12 @@ thunder_bgx_detach(device_t dev) for (lmacid = 0; lmacid < bgx->lmac_count; lmacid++) bgx_lmac_disable(bgx, lmacid); + bgx_vnic[bgx->bgx_id] = NULL; + bus_release_resource(dev, SYS_RES_MEMORY, + rman_get_rid(bgx->reg_base), bgx->reg_base); + free(bgx, M_BGX); + pci_disable_busmaster(dev); + return (0); }