Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Feb 2018 21:01:38 +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: r328950 - in head/sys/dev: mpr mps
Message-ID:  <201802062101.w16L1cdR003728@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: scottl
Date: Tue Feb  6 21:01:38 2018
New Revision: 328950
URL: https://svnweb.freebsd.org/changeset/base/328950

Log:
  Cache the value of the request and reply frame size since it's used quite
  a bit in the normal operation of the driver.  Covert it to represent bytes
  instead of 32bit words.  Fix what I believe to be is a bug in this respect
  with the Tri-mode cards.
  
  Sponsored by:	Netflix

Modified:
  head/sys/dev/mpr/mpr.c
  head/sys/dev/mpr/mpr_user.c
  head/sys/dev/mpr/mprvar.h
  head/sys/dev/mps/mps.c
  head/sys/dev/mps/mps_sas.c
  head/sys/dev/mps/mps_user.c
  head/sys/dev/mps/mpsvar.h

Modified: head/sys/dev/mpr/mpr.c
==============================================================================
--- head/sys/dev/mpr/mpr.c	Tue Feb  6 20:12:05 2018	(r328949)
+++ head/sys/dev/mpr/mpr.c	Tue Feb  6 21:01:38 2018	(r328950)
@@ -1133,6 +1133,14 @@ mpr_send_iocinit(struct mpr_softc *sc)
 	MPR_FUNCTRACE(sc);
 	mpr_dprint(sc, MPR_INIT, "%s entered\n", __func__);
 
+	/* Do a quick sanity check on proper initialization */
+	if ((sc->pqdepth == 0) || (sc->fqdepth == 0) || (sc->reqframesz == 0)
+	    || (sc->replyframesz == 0)) {
+		mpr_dprint(sc, MPR_INIT|MPR_ERROR,
+		    "Driver not fully initialized for IOCInit\n");
+		return (EINVAL);
+	}
+
 	req_sz = sizeof(MPI2_IOC_INIT_REQUEST);
 	reply_sz = sizeof(MPI2_IOC_INIT_REPLY);
 	bzero(&init, req_sz);
@@ -1147,7 +1155,7 @@ mpr_send_iocinit(struct mpr_softc *sc)
 	init.WhoInit = MPI2_WHOINIT_HOST_DRIVER;
 	init.MsgVersion = htole16(MPI2_VERSION);
 	init.HeaderVersion = htole16(MPI2_HEADER_VERSION);
-	init.SystemRequestFrameSize = htole16(sc->facts->IOCRequestFrameSize);
+	init.SystemRequestFrameSize = htole16((uint16_t)(sc->reqframesz / 4));
 	init.ReplyDescriptorPostQueueDepth = htole16(sc->pqdepth);
 	init.ReplyFreeQueueDepth = htole16(sc->fqdepth);
 	init.SenseBufferAddressHigh = 0;
@@ -1303,6 +1311,9 @@ mpr_alloc_replies(struct mpr_softc *sc)
 {
 	int rsize, num_replies;
 
+	/* Store the reply frame size in bytes rather than as 32bit words */
+	sc->replyframesz = sc->facts->ReplyFrameSize * 4;
+
 	/*
 	 * sc->num_replies should be one less than sc->fqdepth.  We need to
 	 * allocate space for sc->fqdepth replies, but only sc->num_replies
@@ -1310,7 +1321,7 @@ mpr_alloc_replies(struct mpr_softc *sc)
 	 */
 	num_replies = max(sc->fqdepth, sc->num_replies);
 
-	rsize = sc->facts->ReplyFrameSize * num_replies * 4; 
+	rsize = sc->replyframesz * num_replies; 
         if (bus_dma_tag_create( sc->mpr_parent_dmat,    /* parent */
 				4, 0,			/* algnmnt, boundary */
 				BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
@@ -1344,7 +1355,10 @@ mpr_alloc_requests(struct mpr_softc *sc)
 	struct mpr_chain *chain;
 	int i, rsize, nsegs;
 
-	rsize = sc->facts->IOCRequestFrameSize * sc->num_reqs * 4;
+	/* Store the request frame size in bytes rather than as 32bit words */
+	sc->reqframesz = sc->facts->IOCRequestFrameSize * 4;
+
+	rsize = sc->reqframesz * sc->num_reqs;
         if (bus_dma_tag_create( sc->mpr_parent_dmat,    /* parent */
 				16, 0,			/* algnmnt, boundary */
 				BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
@@ -1387,7 +1401,7 @@ mpr_alloc_requests(struct mpr_softc *sc)
 			    MPR_MAX_CHAIN_ELEMENT_SIZE;
 		}
 	} else {
-		sc->chain_frame_size = sc->facts->IOCRequestFrameSize * 4;
+		sc->chain_frame_size = sc->reqframesz;
 	}
 	rsize = sc->chain_frame_size * sc->max_chains;
         if (bus_dma_tag_create( sc->mpr_parent_dmat,    /* parent */
@@ -1493,10 +1507,8 @@ mpr_alloc_requests(struct mpr_softc *sc)
 	}
 	for (i = 1; i < sc->num_reqs; i++) {
 		cm = &sc->commands[i];
-		cm->cm_req = sc->req_frames +
-		    i * sc->facts->IOCRequestFrameSize * 4;
-		cm->cm_req_busaddr = sc->req_busaddr +
-		    i * sc->facts->IOCRequestFrameSize * 4;
+		cm->cm_req = sc->req_frames + i * sc->reqframesz;
+		cm->cm_req_busaddr = sc->req_busaddr + i * sc->reqframesz;
 		cm->cm_sense = &sc->sense_frames[i];
 		cm->cm_sense_busaddr = sc->sense_busaddr + i * MPR_SENSE_LEN;
 		cm->cm_desc.Default.SMID = i;
@@ -1621,8 +1633,7 @@ mpr_init_queues(struct mpr_softc *sc)
 	 * Initialize all of the free queue entries.
 	 */
 	for (i = 0; i < sc->fqdepth; i++) {
-		sc->free_queue[i] = sc->reply_busaddr +
-		    (i * sc->facts->ReplyFrameSize * 4);
+		sc->free_queue[i] = sc->reply_busaddr + (i * sc->replyframesz);
 	}
 	sc->replyfreeindex = sc->num_replies;
 
@@ -2419,13 +2430,13 @@ mpr_intr_locked(void *data)
 			 */
 			if ((reply < sc->reply_frames)
 			 || (reply > (sc->reply_frames +
-			     (sc->fqdepth * sc->facts->ReplyFrameSize * 4)))) {
+			     (sc->fqdepth * sc->replyframesz)))) {
 				printf("%s: WARNING: reply %p out of range!\n",
 				       __func__, reply);
 				printf("%s: reply_frames %p, fqdepth %d, "
 				       "frame size %d\n", __func__,
 				       sc->reply_frames, sc->fqdepth,
-				       sc->facts->ReplyFrameSize * 4);
+				       sc->replyframesz);
 				printf("%s: baddr %#x,\n", __func__, baddr);
 				/* LSI-TODO. See Linux Code for Graceful exit */
 				panic("Reply address out of range");
@@ -2963,7 +2974,7 @@ mpr_check_pcie_native_sgl(struct mpr_softc *sc, struct
 	 * put in the main message frame (H/W can only translate an SGL that
 	 * is contained entirely in the main message frame).
 	 */
-	sges_in_segment = (sc->facts->IOCRequestFrameSize -
+	sges_in_segment = (sc->reqframesz -
 	    offsetof(Mpi25SCSIIORequest_t, SGL)) / sizeof(MPI25_SGE_IO_UNION);
 	if (segs_left > sges_in_segment)
 		build_native_sgl = 1;

Modified: head/sys/dev/mpr/mpr_user.c
==============================================================================
--- head/sys/dev/mpr/mpr_user.c	Tue Feb  6 20:12:05 2018	(r328949)
+++ head/sys/dev/mpr/mpr_user.c	Tue Feb  6 21:01:38 2018	(r328950)
@@ -433,7 +433,7 @@ mpr_init_sge(struct mpr_command *cm, void *req, void *
 {
 	int off, space;
 
-	space = (int)cm->cm_sc->facts->IOCRequestFrameSize * 4;
+	space = (int)cm->cm_sc->reqframesz;
 	off = (uintptr_t)sge - (uintptr_t)req;
 
 	KASSERT(off < space, ("bad pointers %p %p, off %d, space %d",
@@ -673,7 +673,7 @@ mpr_user_command(struct mpr_softc *sc, struct mpr_usr_
 	mpr_dprint(sc, MPR_USER, "%s: req %p %d  rpl %p %d\n", __func__,
 	    cmd->req, cmd->req_len, cmd->rpl, cmd->rpl_len);
 
-	if (cmd->req_len > (int)sc->facts->IOCRequestFrameSize * 4) {
+	if (cmd->req_len > (int)sc->reqframesz) {
 		err = EINVAL;
 		goto RetFreeUnlocked;
 	}
@@ -809,7 +809,7 @@ mpr_user_pass_thru(struct mpr_softc *sc, mpr_pass_thru
 	if (err != 0)
 		goto RetFreeUnlocked;
 
-	if (data->RequestSize > (int)sc->facts->IOCRequestFrameSize * 4) {
+	if (data->RequestSize > (int)sc->reqframesz) {
 		err = EINVAL;
 		goto RetFreeUnlocked;
 	}

Modified: head/sys/dev/mpr/mprvar.h
==============================================================================
--- head/sys/dev/mpr/mprvar.h	Tue Feb  6 20:12:05 2018	(r328949)
+++ head/sys/dev/mpr/mprvar.h	Tue Feb  6 21:01:38 2018	(r328950)
@@ -309,6 +309,8 @@ struct mpr_softc {
 #define	MPR_FLAGS_REALLOCATED	(1 << 7)
 	u_int				mpr_debug;
 	int				msi_msgs;
+	u_int				reqframesz;
+	u_int				replyframesz;
 	u_int				atomic_desc_capable;
 	int				tm_cmds_active;
 	int				io_cmds_active;

Modified: head/sys/dev/mps/mps.c
==============================================================================
--- head/sys/dev/mps/mps.c	Tue Feb  6 20:12:05 2018	(r328949)
+++ head/sys/dev/mps/mps.c	Tue Feb  6 21:01:38 2018	(r328950)
@@ -1114,6 +1114,14 @@ mps_send_iocinit(struct mps_softc *sc)
 	MPS_FUNCTRACE(sc);
 	mps_dprint(sc, MPS_INIT, "%s entered\n", __func__);
 
+	/* Do a quick sanity check on proper initialization */
+	if ((sc->pqdepth == 0) || (sc->fqdepth == 0) || (sc->reqframesz == 0)
+	    || (sc->replyframesz == 0)) {
+		mps_dprint(sc, MPS_INIT|MPS_ERROR,
+		    "Driver not fully initialized for IOCInit\n");
+		return (EINVAL);
+	}
+
 	req_sz = sizeof(MPI2_IOC_INIT_REQUEST);
 	reply_sz = sizeof(MPI2_IOC_INIT_REPLY);
 	bzero(&init, req_sz);
@@ -1128,7 +1136,7 @@ mps_send_iocinit(struct mps_softc *sc)
 	init.WhoInit = MPI2_WHOINIT_HOST_DRIVER;
 	init.MsgVersion = htole16(MPI2_VERSION);
 	init.HeaderVersion = htole16(MPI2_HEADER_VERSION);
-	init.SystemRequestFrameSize = htole16(sc->facts->IOCRequestFrameSize);
+	init.SystemRequestFrameSize = htole16((uint16_t)(sc->reqframesz / 4));
 	init.ReplyDescriptorPostQueueDepth = htole16(sc->pqdepth);
 	init.ReplyFreeQueueDepth = htole16(sc->fqdepth);
 	init.SenseBufferAddressHigh = 0;
@@ -1282,6 +1290,9 @@ mps_alloc_replies(struct mps_softc *sc)
 {
 	int rsize, num_replies;
 
+	/* Store the reply frame size in bytes rather than as 32bit words */
+	sc->replyframesz = sc->facts->ReplyFrameSize * 4;
+
 	/*
 	 * sc->num_replies should be one less than sc->fqdepth.  We need to
 	 * allocate space for sc->fqdepth replies, but only sc->num_replies
@@ -1289,7 +1300,7 @@ mps_alloc_replies(struct mps_softc *sc)
 	 */
 	num_replies = max(sc->fqdepth, sc->num_replies);
 
-	rsize = sc->facts->ReplyFrameSize * num_replies * 4; 
+	rsize = sc->replyframesz * num_replies; 
         if (bus_dma_tag_create( sc->mps_parent_dmat,    /* parent */
 				4, 0,			/* algnmnt, boundary */
 				BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
@@ -1323,7 +1334,10 @@ mps_alloc_requests(struct mps_softc *sc)
 	struct mps_chain *chain;
 	int i, rsize, nsegs;
 
-	rsize = sc->facts->IOCRequestFrameSize * sc->num_reqs * 4;
+	/* Store the request frame size in bytes rather than as 32bit words */
+	sc->reqframesz = sc->facts->IOCRequestFrameSize * 4;
+
+	rsize = sc->reqframesz * sc->num_reqs;
         if (bus_dma_tag_create( sc->mps_parent_dmat,    /* parent */
 				16, 0,			/* algnmnt, boundary */
 				BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
@@ -1347,7 +1361,7 @@ mps_alloc_requests(struct mps_softc *sc)
         bus_dmamap_load(sc->req_dmat, sc->req_map, sc->req_frames, rsize,
 	    mps_memaddr_cb, &sc->req_busaddr, 0);
 
-	rsize = sc->facts->IOCRequestFrameSize * sc->max_chains * 4;
+	rsize = sc->reqframesz * sc->max_chains;
         if (bus_dma_tag_create( sc->mps_parent_dmat,    /* parent */
 				16, 0,			/* algnmnt, boundary */
 				BUS_SPACE_MAXADDR_32BIT,/* lowaddr */
@@ -1404,9 +1418,9 @@ mps_alloc_requests(struct mps_softc *sc)
 	for (i = 0; i < sc->max_chains; i++) {
 		chain = &sc->chains[i];
 		chain->chain = (MPI2_SGE_IO_UNION *)(sc->chain_frames +
-		    i * sc->facts->IOCRequestFrameSize * 4);
+		    i * sc->reqframesz);
 		chain->chain_busaddr = sc->chain_busaddr +
-		    i * sc->facts->IOCRequestFrameSize * 4;
+		    i * sc->reqframesz;
 		mps_free_chain(sc, chain);
 		sc->chain_free_lowwater++;
 	}
@@ -1441,10 +1455,8 @@ mps_alloc_requests(struct mps_softc *sc)
 	}
 	for (i = 1; i < sc->num_reqs; i++) {
 		cm = &sc->commands[i];
-		cm->cm_req = sc->req_frames +
-		    i * sc->facts->IOCRequestFrameSize * 4;
-		cm->cm_req_busaddr = sc->req_busaddr +
-		    i * sc->facts->IOCRequestFrameSize * 4;
+		cm->cm_req = sc->req_frames + i * sc->reqframesz;
+		cm->cm_req_busaddr = sc->req_busaddr + i * sc->reqframesz;
 		cm->cm_sense = &sc->sense_frames[i];
 		cm->cm_sense_busaddr = sc->sense_busaddr + i * MPS_SENSE_LEN;
 		cm->cm_desc.Default.SMID = i;
@@ -1487,7 +1499,7 @@ mps_init_queues(struct mps_softc *sc)
 	 * Initialize all of the free queue entries.
 	 */
 	for (i = 0; i < sc->fqdepth; i++)
-		sc->free_queue[i] = sc->reply_busaddr + (i * sc->facts->ReplyFrameSize * 4);
+		sc->free_queue[i] = sc->reply_busaddr + (i * sc->replyframesz);
 	sc->replyfreeindex = sc->num_replies;
 
 	return (0);
@@ -2279,13 +2291,13 @@ mps_intr_locked(void *data)
 			 */
 			if ((reply < sc->reply_frames)
 			 || (reply > (sc->reply_frames +
-			     (sc->fqdepth * sc->facts->ReplyFrameSize * 4)))) {
+			     (sc->fqdepth * sc->replyframesz)))) {
 				printf("%s: WARNING: reply %p out of range!\n",
 				       __func__, reply);
 				printf("%s: reply_frames %p, fqdepth %d, "
 				       "frame size %d\n", __func__,
 				       sc->reply_frames, sc->fqdepth,
-				       sc->facts->ReplyFrameSize * 4);
+				       sc->replyframesz);
 				printf("%s: baddr %#x,\n", __func__, baddr);
 				/* LSI-TODO. See Linux Code. Need Graceful exit*/
 				panic("Reply address out of range");
@@ -2553,7 +2565,7 @@ mps_add_chain(struct mps_command *cm)
 {
 	MPI2_SGE_CHAIN32 *sgc;
 	struct mps_chain *chain;
-	int space;
+	u_int space;
 
 	if (cm->cm_sglsize < MPS_SGC_SIZE)
 		panic("MPS: Need SGE Error Code\n");
@@ -2562,7 +2574,7 @@ mps_add_chain(struct mps_command *cm)
 	if (chain == NULL)
 		return (ENOBUFS);
 
-	space = (int)cm->cm_sc->facts->IOCRequestFrameSize * 4;
+	space = cm->cm_sc->reqframesz;
 
 	/*
 	 * Note: a double-linked list is used to make it easier to

Modified: head/sys/dev/mps/mps_sas.c
==============================================================================
--- head/sys/dev/mps/mps_sas.c	Tue Feb  6 20:12:05 2018	(r328949)
+++ head/sys/dev/mps/mps_sas.c	Tue Feb  6 21:01:38 2018	(r328950)
@@ -997,7 +997,7 @@ mpssas_action(struct cam_sim *sim, union ccb *ccb)
 		 * user's value and the calculated value as long as the user's
 		 * value is larger than 0. The user's value is in pages.
 		 */
-		sges_per_frame = ((sc->facts->IOCRequestFrameSize * 4) /
+		sges_per_frame = ((sc->reqframesz) /
 		    sizeof(MPI2_SGE_SIMPLE64)) - 1;
 		cpi->maxio = (sges_per_frame * sc->facts->MaxChainDepth) + 1;
 		cpi->maxio *= PAGE_SIZE;

Modified: head/sys/dev/mps/mps_user.c
==============================================================================
--- head/sys/dev/mps/mps_user.c	Tue Feb  6 20:12:05 2018	(r328949)
+++ head/sys/dev/mps/mps_user.c	Tue Feb  6 21:01:38 2018	(r328950)
@@ -420,7 +420,7 @@ mpi_init_sge(struct mps_command *cm, void *req, void *
 {
 	int off, space;
 
-	space = (int)cm->cm_sc->facts->IOCRequestFrameSize * 4;
+	space = (int)cm->cm_sc->reqframesz;
 	off = (uintptr_t)sge - (uintptr_t)req;
 
 	KASSERT(off < space, ("bad pointers %p %p, off %d, space %d",
@@ -688,7 +688,7 @@ mps_user_command(struct mps_softc *sc, struct mps_usr_
 	mps_dprint(sc, MPS_USER, "%s: req %p %d  rpl %p %d\n", __func__,
 	    cmd->req, cmd->req_len, cmd->rpl, cmd->rpl_len);
 
-	if (cmd->req_len > (int)sc->facts->IOCRequestFrameSize * 4) {
+	if (cmd->req_len > (int)sc->reqframesz) {
 		err = EINVAL;
 		goto RetFreeUnlocked;
 	}
@@ -821,7 +821,7 @@ mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru
 	if (err != 0)
 		goto RetFreeUnlocked;
 
-	if (data->RequestSize > (int)sc->facts->IOCRequestFrameSize * 4) {
+	if (data->RequestSize > (int)sc->reqframesz) {
 		err = EINVAL;
 		goto RetFreeUnlocked;
 	}

Modified: head/sys/dev/mps/mpsvar.h
==============================================================================
--- head/sys/dev/mps/mpsvar.h	Tue Feb  6 20:12:05 2018	(r328949)
+++ head/sys/dev/mps/mpsvar.h	Tue Feb  6 21:01:38 2018	(r328950)
@@ -307,6 +307,8 @@ struct mps_softc {
 #define	MPS_FLAGS_REALLOCATED	(1 << 7)
 	u_int				mps_debug;
 	u_int				msi_msgs;
+	u_int				reqframesz;
+	u_int				replyframesz;
 	int				tm_cmds_active;
 	int				io_cmds_active;
 	int				io_cmds_highwater;



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