Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Sep 2017 04:09:18 +0000 (UTC)
From:      Scott Long <scottl@FreeBSD.org>
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
Message-ID:  <201709100409.v8A49ITh091369@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201709100409.v8A49ITh091369>