From owner-svn-src-head@freebsd.org Sun Sep 10 04:09:20 2017 Return-Path: Delivered-To: svn-src-head@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 F1E17E1F4AB; Sun, 10 Sep 2017 04:09:19 +0000 (UTC) (envelope-from scottl@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 CC2EE6471E; Sun, 10 Sep 2017 04:09:19 +0000 (UTC) (envelope-from scottl@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8A49Jl8091371; Sun, 10 Sep 2017 04:09:19 GMT (envelope-from scottl@FreeBSD.org) Received: (from scottl@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8A49ITh091369; Sun, 10 Sep 2017 04:09:18 GMT (envelope-from scottl@FreeBSD.org) Message-Id: <201709100409.v8A49ITh091369@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: scottl set sender to scottl@FreeBSD.org using -f From: Scott Long Date: Sun, 10 Sep 2017 04:09:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r323383 - in head/sys/dev: mpr mps X-SVN-Group: head X-SVN-Commit-Author: scottl X-SVN-Commit-Paths: in head/sys/dev: mpr mps X-SVN-Commit-Revision: 323383 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Sep 2017 04:09:20 -0000 Author: scottl Date: Sun Sep 10 04:09:18 2017 New Revision: 323383 URL: https://svnweb.freebsd.org/changeset/base/323383 Log: More code refactoring in preparation for enabling multiqueue. Sponsored by: Netflix Modified: head/sys/dev/mpr/mpr.c head/sys/dev/mps/mps.c Modified: head/sys/dev/mpr/mpr.c ============================================================================== --- head/sys/dev/mpr/mpr.c Sun Sep 10 01:25:15 2017 (r323382) +++ head/sys/dev/mpr/mpr.c Sun Sep 10 04:09:18 2017 (r323383) @@ -89,6 +89,7 @@ static void mpr_iocfacts_free(struct mpr_softc *sc); static void mpr_startup(void *arg); static int mpr_send_iocinit(struct mpr_softc *sc); static int mpr_alloc_queues(struct mpr_softc *sc); +static int mpr_alloc_hw_queues(struct mpr_softc *sc); static int mpr_alloc_replies(struct mpr_softc *sc); static int mpr_alloc_requests(struct mpr_softc *sc); static int mpr_alloc_nvme_prp_pages(struct mpr_softc *sc); @@ -565,22 +566,24 @@ mpr_iocfacts_allocate(struct mpr_softc *sc, uint8_t at * IOC Facts are different from the previous IOC Facts after a Diag * Reset. Targets have already been allocated above if needed. */ - if (attaching || reallocating) { - if (((error = mpr_alloc_queues(sc)) != 0) || - ((error = mpr_alloc_replies(sc)) != 0) || - ((error = mpr_alloc_requests(sc)) != 0)) { - if (attaching ) { - mpr_dprint(sc, MPR_INIT|MPR_ERROR, - "Failed to alloc queues with error %d\n", - error); - mpr_free(sc); - return (error); - } else { - panic("%s failed to alloc queues with error " - "%d\n", __func__, error); - } - } + error = 0; + while (attaching || reallocating) { + if ((error = mpr_alloc_hw_queues(sc)) != 0) + break; + if ((error = mpr_alloc_replies(sc)) != 0) + break; + if ((error = mpr_alloc_requests(sc)) != 0) + break; + if ((error = mpr_alloc_queues(sc)) != 0) + break; + break; } + if (error) { + mpr_dprint(sc, MPR_INIT|MPR_ERROR, + "Failed to alloc queues with error %d\n", error); + mpr_free(sc); + return (error); + } /* Always initialize the queues */ bzero(sc->free_queue, sc->fqdepth * 4); @@ -593,15 +596,10 @@ mpr_iocfacts_allocate(struct mpr_softc *sc, uint8_t at */ error = mpr_transition_operational(sc); if (error != 0) { - if (attaching) { - mpr_dprint(sc, MPR_INIT|MPR_FAULT, "Failed to " - "transition to operational with error %d\n", error); - mpr_free(sc); - return (error); - } else { - panic("%s failed to transition to operational with " - "error %d\n", __func__, error); - } + mpr_dprint(sc, MPR_INIT|MPR_FAULT, "Failed to " + "transition to operational with error %d\n", error); + mpr_free(sc); + return (error); } /* @@ -620,26 +618,31 @@ mpr_iocfacts_allocate(struct mpr_softc *sc, uint8_t at /* * Attach the subsystems so they can prepare their event masks. + * XXX Should be dynamic so that IM/IR and user modules can attach */ - /* XXX Should be dynamic so that IM/IR and user modules can attach */ - if (attaching) { + error = 0; + while (attaching) { mpr_dprint(sc, MPR_INIT, "Attaching subsystems\n"); - if (((error = mpr_attach_log(sc)) != 0) || - ((error = mpr_attach_sas(sc)) != 0) || - ((error = mpr_attach_user(sc)) != 0)) { - mpr_dprint(sc, MPR_INIT|MPR_ERROR, - "Failed to attach all subsystems: error %d\n", - error); - mpr_free(sc); - return (error); - } + if ((error = mpr_attach_log(sc)) != 0) + break; + if ((error = mpr_attach_sas(sc)) != 0) + break; + if ((error = mpr_attach_user(sc)) != 0) + break; + break; + } + if (error) { + mpr_dprint(sc, MPR_INIT|MPR_ERROR, + "Failed to attach all subsystems: error %d\n", error); + mpr_free(sc); + return (error); + } - if ((error = mpr_pci_setup_interrupts(sc)) != 0) { - mpr_dprint(sc, MPR_INIT|MPR_ERROR, - "Failed to setup interrupts\n"); - mpr_free(sc); - return (error); - } + if ((error = mpr_pci_setup_interrupts(sc)) != 0) { + mpr_dprint(sc, MPR_INIT|MPR_ERROR, + "Failed to setup interrupts\n"); + mpr_free(sc); + return (error); } return (error); @@ -1140,10 +1143,8 @@ mpr_memaddr_cb(void *arg, bus_dma_segment_t *segs, int static int mpr_alloc_queues(struct mpr_softc *sc) { - bus_addr_t queues_busaddr; struct mpr_queue *q; - uint8_t *queues; - int qsize, fqsize, pqsize, nq, i; + int nq, i; nq = MIN(sc->msi_msgs, mp_ncpus); sc->msi_msgs = nq; @@ -1159,6 +1160,15 @@ mpr_alloc_queues(struct mpr_softc *sc) q->sc = sc; q->qnum = i; } + return (0); +} + +static int +mpr_alloc_hw_queues(struct mpr_softc *sc) +{ + bus_addr_t queues_busaddr; + uint8_t *queues; + int qsize, fqsize, pqsize; /* * The reply free queue contains 4 byte entries in multiples of 16 and Modified: head/sys/dev/mps/mps.c ============================================================================== --- head/sys/dev/mps/mps.c Sun Sep 10 01:25:15 2017 (r323382) +++ head/sys/dev/mps/mps.c Sun Sep 10 04:09:18 2017 (r323383) @@ -87,6 +87,7 @@ static void mps_iocfacts_free(struct mps_softc *sc); static void mps_startup(void *arg); static int mps_send_iocinit(struct mps_softc *sc); static int mps_alloc_queues(struct mps_softc *sc); +static int mps_alloc_hw_queues(struct mps_softc *sc); static int mps_alloc_replies(struct mps_softc *sc); static int mps_alloc_requests(struct mps_softc *sc); static int mps_attach_log(struct mps_softc *sc); @@ -552,22 +553,25 @@ mps_iocfacts_allocate(struct mps_softc *sc, uint8_t at * IOC Facts are different from the previous IOC Facts after a Diag * Reset. Targets have already been allocated above if needed. */ - if (attaching || reallocating) { - if (((error = mps_alloc_queues(sc)) != 0) || - ((error = mps_alloc_replies(sc)) != 0) || - ((error = mps_alloc_requests(sc)) != 0)) { - if (attaching ) { - mps_dprint(sc, MPS_INIT|MPS_FAULT, - "Failed to alloc queues with error %d\n", - error); - mps_free(sc); - return (error); - } else { - panic("%s failed to alloc queues with error " - "%d\n", __func__, error); - } - } + error = 0; + while (attaching || reallocating) { + if ((error = mps_alloc_hw_queues(sc)) != 0) + break; + if ((error = mps_alloc_replies(sc)) != 0) + break; + if ((error = mps_alloc_requests(sc)) != 0) + break; + if ((error = mps_alloc_queues(sc)) != 0) + break; + + break; } + if (error) { + mps_dprint(sc, MPS_INIT|MPS_FAULT, + "Failed to alloc queues with error %d\n", error); + mps_free(sc); + return (error); + } /* Always initialize the queues */ bzero(sc->free_queue, sc->fqdepth * 4); @@ -580,15 +584,10 @@ mps_iocfacts_allocate(struct mps_softc *sc, uint8_t at */ error = mps_transition_operational(sc); if (error != 0) { - if (attaching) { - mps_dprint(sc, MPS_INIT|MPS_FAULT, "Failed to " - "transition to operational with error %d\n", error); - mps_free(sc); - return (error); - } else { - panic("%s failed to transition to operational with " - "error %d\n", __func__, error); - } + mps_dprint(sc, MPS_INIT|MPS_FAULT, "Failed to " + "transition to operational with error %d\n", error); + mps_free(sc); + return (error); } /* @@ -607,25 +606,31 @@ mps_iocfacts_allocate(struct mps_softc *sc, uint8_t at /* * Attach the subsystems so they can prepare their event masks. + * XXX Should be dynamic so that IM/IR and user modules can attach */ - /* XXX Should be dynamic so that IM/IR and user modules can attach */ - if (attaching) { + error = 0; + while (attaching) { mps_dprint(sc, MPS_INIT, "Attaching subsystems\n"); - if (((error = mps_attach_log(sc)) != 0) || - ((error = mps_attach_sas(sc)) != 0) || - ((error = mps_attach_user(sc)) != 0)) { - mps_dprint(sc, MPS_INIT|MPS_FAULT,"Failed to attach " - "all subsystems: error %d\n", error); - mps_free(sc); - return (error); - } + if ((error = mps_attach_log(sc)) != 0) + break; + if ((error = mps_attach_sas(sc)) != 0) + break; + if ((error = mps_attach_user(sc)) != 0) + break; + break; + } + if (error) { + mps_dprint(sc, MPS_INIT|MPS_FAULT, "Failed to attach all " + "subsystems: error %d\n", error); + mps_free(sc); + return (error); + } - if ((error = mps_pci_setup_interrupts(sc)) != 0) { - mps_dprint(sc, MPS_INIT|MPS_FAULT, "Failed to setup " - "interrupts\n"); - mps_free(sc); - return (error); - } + if ((error = mps_pci_setup_interrupts(sc)) != 0) { + mps_dprint(sc, MPS_INIT|MPS_FAULT, "Failed to setup " + "interrupts\n"); + mps_free(sc); + return (error); } /* @@ -1113,10 +1118,8 @@ mps_memaddr_cb(void *arg, bus_dma_segment_t *segs, int static int mps_alloc_queues(struct mps_softc *sc) { - bus_addr_t queues_busaddr; struct mps_queue *q; - uint8_t *queues; - int qsize, fqsize, pqsize, nq, i; + int nq, i; nq = MIN(sc->msi_msgs, mp_ncpus); sc->msi_msgs = nq; @@ -1132,6 +1135,16 @@ mps_alloc_queues(struct mps_softc *sc) q->sc = sc; q->qnum = i; } + + return (0); +} + +static int +mps_alloc_hw_queues(struct mps_softc *sc) +{ + bus_addr_t queues_busaddr; + uint8_t *queues; + int qsize, fqsize, pqsize; /* * The reply free queue contains 4 byte entries in multiples of 16 and