Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 May 2017 18:59:18 +0000 (UTC)
From:      "Kenneth D. Merry" <ken@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r318148 - stable/11/sys/dev/isp
Message-ID:  <201705101859.v4AIxIQ9091502@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ken
Date: Wed May 10 18:59:18 2017
New Revision: 318148
URL: https://svnweb.freebsd.org/changeset/base/318148

Log:
  MFC r317740:
  
    Correct loop mode CRN resets to adhere to FCP-4 section 4.10
  
    Prior to this change, the CRN (Command Reference Number) is reset on any
    firmware LIP, LOOP DOWN, or LOOP RESET event in violation of FCP-4 which
    specifies that the CRN should only be reset in response to a LIP Reset
    (LIPyx) primitive. FCP-4 also indicates PLOGI/LOGO and PRLI/PRLO ELS
    actions as conditions for resetting the CRN for the associated initiator
    port.
  
    These violations manifest themselves when the HBA is removed from the
    loop, or a target device is removed (especially during an outstanding
    command) without power cycling. If the HBA and and the target device
    determine upon re-establishing the loop that no PLOGI or PRLI is
    required, and the target does not issue a LIPxy to the initiator, the
    CRN for the target will have been improperly reset by the isp driver. As
    a result, the target port will silently ignore all FCP commands issued
    during the device probe (which will time out) preventing the device from
    attaching.
  
    This change corrects thie CRN reset behavior in response to loop state
    changes, also introduces CRN resets for the above mentioned ELS actions
    as encountered through async PDB change events.
  
    This change also adds cleanup of outstanding commands in isp_loop_dead()
    that was previously missing.
  
    sys/dev/isp/isp.c
    	Add the last login state to debug output when syncing the pdb
  
    sys/dev/isp/isp_freebsd.c
    	Replace binary statement setting aborted ccb status in
    	isp_watchdog() with the XS_SETERR macro used elsewhere
  
    	In isp_loop_dead(), abort or complete pending commands as done
    	in isp_watchdog()
  
    	In isp_async(), segregate the ISPASYNC_LOOP_RESET action from
    	ISPASYNC_LIP, ISPASYNC_LOOP_DOWN, and ISPASYNC_LOOP_UP
    	fallthroughs, and only reset the CRN in the RESET case. Also add
    	checks to handle false LOOP RESET actions that do not have a
    	proper associated LIP primitive, and log the primitive in the
    	debug messages
  
    	In isp_async(), remove the goto from ISP_ASYNC_DEV_STAYED, and
    	only reset the CRN in the DEV_CHANGED action
  
    	In isp_async(), when processing an ISPASYNC_CHANGE_PDB status,
    	reset CRN(s) for the associated nphdl (or all ports) if the
    	change reason is some form of ELS login/logout. Also remove
    	assignment to fc since it is not used in the scope
  
    sys/dev/isp/ispmbox.h
    	Add macro definition for the global N-Port handle, and correct a
    	macro typo 'PDB24XX_AE_PRLI_DONJE'
  
    sys/dev/isp/ispvar.h
    	Add macros FCP_AL_DA_ALL, FCP_AL_PA, and FCP_IS_DEST_ALPD for
    	more legible code when determining if an AL_PD port matches the
    	portid for a given struct fcparam* by value or by virtue of the
    	AL_PD port being 0xFF
  
  Submitted by:	Reid Linnemann
  Sponsored by:	Spectra Logic

Modified:
  stable/11/sys/dev/isp/isp.c
  stable/11/sys/dev/isp/isp_freebsd.c
  stable/11/sys/dev/isp/ispmbox.h
  stable/11/sys/dev/isp/ispvar.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/isp/isp.c
==============================================================================
--- stable/11/sys/dev/isp/isp.c	Wed May 10 18:33:40 2017	(r318147)
+++ stable/11/sys/dev/isp/isp.c	Wed May 10 18:59:18 2017	(r318148)
@@ -2771,10 +2771,11 @@ isp_getpdb(ispsoftc_t *isp, int chan, ui
 		pdb->portid = BITS2WORD_24XX(un.bill.pdb_portid_bits);
 		ISP_MEMCPY(pdb->portname, un.bill.pdb_portname, 8);
 		ISP_MEMCPY(pdb->nodename, un.bill.pdb_nodename, 8);
-		isp_prt(isp, ISP_LOGDEBUG1,
-		    "Chan %d handle 0x%x Port 0x%06x flags 0x%x curstate %x",
+		isp_prt(isp, ISP_LOGDEBUG0,
+		    "Chan %d handle 0x%x Port 0x%06x flags 0x%x curstate %x laststate %x",
 		    chan, id, pdb->portid, un.bill.pdb_flags,
-		    un.bill.pdb_curstate);
+		    un.bill.pdb_curstate, un.bill.pdb_laststate);
+
 		if (un.bill.pdb_curstate < PDB2400_STATE_PLOGI_DONE || un.bill.pdb_curstate > PDB2400_STATE_LOGGED_IN) {
 			mbs.param[0] = MBOX_NOT_LOGGED_IN;
 			return (mbs.param[0]);

Modified: stable/11/sys/dev/isp/isp_freebsd.c
==============================================================================
--- stable/11/sys/dev/isp/isp_freebsd.c	Wed May 10 18:33:40 2017	(r318147)
+++ stable/11/sys/dev/isp/isp_freebsd.c	Wed May 10 18:59:18 2017	(r318148)
@@ -2567,8 +2567,7 @@ isp_watchdog(void *arg)
 		} 
 		isp_destroy_handle(isp, handle);
 		isp_prt(isp, ISP_LOGERR, "%s: timeout for handle 0x%x", __func__, handle);
-		xs->ccb_h.status &= ~CAM_STATUS_MASK;
-		xs->ccb_h.status |= CAM_CMD_TIMEOUT;
+		XS_SETERR(xs, CAM_CMD_TIMEOUT);
 		isp_done(xs);
 	} else {
 		if (ohandle != ISP_HANDLE_FREE) {
@@ -2739,9 +2738,6 @@ isp_loop_dead(ispsoftc_t *isp, int chan)
 		if (lp->state == FC_PORTDB_STATE_NIL)
 			continue;
 
-		/*
-		 * XXX: CLEAN UP AND COMPLETE ANY PENDING COMMANDS FIRST!
-		 */
 		for (i = 0; i < isp->isp_maxcmds; i++) {
 			struct ccb_scsiio *xs;
 
@@ -2757,6 +2753,25 @@ isp_loop_dead(ispsoftc_t *isp, int chan)
 			isp_prt(isp, ISP_LOGWARN, "command handle 0x%x for %d.%d.%jx orphaned by loop down timeout",
 			    isp->isp_xflist[i].handle, chan, XS_TGT(xs),
 			    (uintmax_t)XS_LUN(xs));
+
+			/*
+			 * Just like in isp_watchdog, abort the outstanding
+			 * command or immediately free its resources if it is
+			 * not active
+			 */
+			if (isp_control(isp, ISPCTL_ABORT_CMD, xs) == 0) {
+				continue;
+			}
+
+			if (XS_XFRLEN(xs)) {
+				ISP_DMAFREE(isp, xs, isp->isp_xflist[i].handle);
+			}
+			isp_destroy_handle(isp, isp->isp_xflist[i].handle);
+			isp_prt(isp, ISP_LOGWARN, "command handle 0x%x for %d.%d.%jx could not be aborted and was destroyed",
+			    isp->isp_xflist[i].handle, chan, XS_TGT(xs),
+			    (uintmax_t)XS_LUN(xs));
+			XS_SETERR(xs, HBA_BUSRESET);
+			isp_done(xs);
 		}
 
 		isp_prt(isp, ISP_LOGCONFIG, prom3, chan, dbidx, lp->portid, "Loop Down Timeout");
@@ -3562,7 +3577,7 @@ isp_async(ispsoftc_t *isp, ispasync_t cm
 	static const char prom[] = "Chan %d [%d] WWPN 0x%16jx PortID 0x%06x handle 0x%x %s %s";
 	char buf[64];
 	char *msg = NULL;
-	target_id_t tgt;
+	target_id_t tgt = 0;
 	fcportdb_t *lp;
 	struct isp_fc *fc;
 	struct cam_path *tmppath;
@@ -3639,30 +3654,50 @@ isp_async(ispsoftc_t *isp, ispasync_t cm
 		}
 		break;
 	}
+	case ISPASYNC_LOOP_RESET:
+	{
+		uint16_t lipp;
+		fcparam *fcp;
+		va_start(ap, cmd);
+		bus = va_arg(ap, int);
+		va_end(ap);
+
+		lipp = ISP_READ(isp, OUTMAILBOX1);
+		fcp = FCPARAM(isp, bus);
+		
+		isp_prt(isp, ISP_LOGINFO, "Chan %d LOOP Reset, LIP primitive %x", bus, lipp);
+		/* 
+		 * Per FCP-4, a Reset LIP should result in a CRN reset. Other
+		 * LIPs and loop up/down events should never reset the CRN. For
+		 * an as of yet unknown reason, 24xx series cards (and
+		 * potentially others) can interrupt with a LIP Reset status
+		 * when no LIP reset came down the wire. Additionally, the LIP
+		 * primitive accompanying this status would not be a valid LIP
+		 * Reset primitive, but some variation of an invalid AL_PA
+		 * LIP. As a result, we have to verify the AL_PD in the LIP
+		 * addresses our port before blindly resetting.
+		*/
+		if (FCP_IS_DEST_ALPD(fcp, (lipp & 0x00FF)))
+			isp_fcp_reset_crn(isp, bus, /*tgt*/0, /*tgt_set*/ 0);
+		isp_loop_changed(isp, bus);
+		break;
+	}
 	case ISPASYNC_LIP:
 		if (msg == NULL)
 			msg = "LIP Received";
 		/* FALLTHROUGH */
-	case ISPASYNC_LOOP_RESET:
-		if (msg == NULL)
-			msg = "LOOP Reset";
-		/* FALLTHROUGH */
 	case ISPASYNC_LOOP_DOWN:
 		if (msg == NULL)
 			msg = "LOOP Down";
-		va_start(ap, cmd);
-		bus = va_arg(ap, int);
-		va_end(ap);
-		isp_fcp_reset_crn(isp, bus, /*tgt*/0, /*tgt_set*/ 0);
-		isp_loop_changed(isp, bus);
-		isp_prt(isp, ISP_LOGINFO, "Chan %d %s", bus, msg);
-		break;
+		/* FALLTHROUGH */
 	case ISPASYNC_LOOP_UP:
+		if (msg == NULL)
+			msg = "LOOP Up";
 		va_start(ap, cmd);
 		bus = va_arg(ap, int);
 		va_end(ap);
 		isp_loop_changed(isp, bus);
-		isp_prt(isp, ISP_LOGINFO, "Chan %d Loop UP", bus);
+		isp_prt(isp, ISP_LOGINFO, "Chan %d %s", bus, msg);
 		break;
 	case ISPASYNC_DEV_ARRIVED:
 		va_start(ap, cmd);
@@ -3692,6 +3727,7 @@ isp_async(ispsoftc_t *isp, ispasync_t cm
 		}
 		break;
 	case ISPASYNC_DEV_CHANGED:
+	case ISPASYNC_DEV_STAYED:		
 		va_start(ap, cmd);
 		bus = va_arg(ap, int);
 		lp = va_arg(ap, fcportdb_t *);
@@ -3699,18 +3735,23 @@ isp_async(ispsoftc_t *isp, ispasync_t cm
 		fc = ISP_FC_PC(isp, bus);
 		tgt = FC_PORTDB_TGT(isp, bus, lp);
 		isp_gen_role_str(buf, sizeof (buf), lp->new_prli_word3);
-		isp_prt(isp, ISP_LOGCONFIG, prom, bus, tgt, lp->port_wwn, lp->new_portid, lp->handle, buf, "changed");
-changed:
+		if (cmd == ISPASYNC_DEV_CHANGED)
+			isp_prt(isp, ISP_LOGCONFIG, prom, bus, tgt, lp->port_wwn, lp->new_portid, lp->handle, buf, "changed");
+		else
+			isp_prt(isp, ISP_LOGCONFIG, prom, bus, tgt, lp->port_wwn, lp->portid, lp->handle, buf, "stayed");			
+
 		if (lp->is_target !=
 		    ((FCPARAM(isp, bus)->role & ISP_ROLE_INITIATOR) &&
 		     (lp->new_prli_word3 & PRLI_WD3_TARGET_FUNCTION))) {
 			lp->is_target = !lp->is_target;
 			if (lp->is_target) {
-				isp_fcp_reset_crn(isp, bus, tgt, /*tgt_set*/ 1);
+				if (cmd == ISPASYNC_DEV_CHANGED)
+					isp_fcp_reset_crn(isp, bus, tgt, /*tgt_set*/ 1);
 				isp_make_here(isp, lp, bus, tgt);
 			} else {
 				isp_make_gone(isp, lp, bus, tgt);
-				isp_fcp_reset_crn(isp, bus, tgt, /*tgt_set*/ 1);
+				if (cmd == ISPASYNC_DEV_CHANGED)
+					isp_fcp_reset_crn(isp, bus, tgt, /*tgt_set*/ 1);
 			}
 		}
 		if (lp->is_initiator !=
@@ -3726,16 +3767,6 @@ changed:
 			xpt_async(AC_CONTRACT, fc->path, &ac);
 		}
 		break;
-	case ISPASYNC_DEV_STAYED:
-		va_start(ap, cmd);
-		bus = va_arg(ap, int);
-		lp = va_arg(ap, fcportdb_t *);
-		va_end(ap);
-		fc = ISP_FC_PC(isp, bus);
-		tgt = FC_PORTDB_TGT(isp, bus, lp);
-		isp_gen_role_str(buf, sizeof (buf), lp->prli_word3);
-		isp_prt(isp, ISP_LOGCONFIG, prom, bus, tgt, lp->port_wwn, lp->portid, lp->handle, buf, "stayed");
-		goto changed;
 	case ISPASYNC_DEV_GONE:
 		va_start(ap, cmd);
 		bus = va_arg(ap, int);
@@ -3781,10 +3812,45 @@ changed:
 		va_end(ap);
 
 		if (evt == ISPASYNC_CHANGE_PDB) {
+			int tgt_set = 0;
 			msg = "Port Database Changed";
 			isp_prt(isp, ISP_LOGINFO,
 			    "Chan %d %s (nphdl 0x%x state 0x%x reason 0x%x)",
 			    bus, msg, nphdl, nlstate, reason);
+			/*
+			 * Port database syncs are not sufficient for
+			 * determining that logins or logouts are done on the
+			 * loop, but this information is directly available from
+			 * the reason code from the incoming mbox. We must reset
+			 * the fcp crn on these events according to FCP-4
+			 */
+			switch (reason) {
+			case PDB24XX_AE_IMPL_LOGO_1:
+			case PDB24XX_AE_IMPL_LOGO_2:
+			case PDB24XX_AE_IMPL_LOGO_3:
+			case PDB24XX_AE_PLOGI_RCVD:
+			case PDB24XX_AE_PRLI_RCVD:
+			case PDB24XX_AE_PRLO_RCVD:
+			case PDB24XX_AE_LOGO_RCVD:
+			case PDB24XX_AE_PLOGI_DONE:
+			case PDB24XX_AE_PRLI_DONE:
+				/*
+				 * If the event is not global, twiddle tgt and
+				 * tgt_set to nominate only the target
+				 * associated with the nphdl.
+				 */
+				if (nphdl != PDB24XX_AE_GLOBAL) {
+					/* Break if we don't yet have the pdb */
+					if (!isp_find_pdb_by_handle(isp, bus, nphdl, &lp))
+						break;
+					tgt = FC_PORTDB_TGT(isp, bus, lp);
+					tgt_set = 1;
+				}
+				isp_fcp_reset_crn(isp, bus, tgt, tgt_set);
+				break;
+			default:
+				break; /* NOP */
+			}
 		} else if (evt == ISPASYNC_CHANGE_SNS) {
 			msg = "Name Server Database Changed";
 			isp_prt(isp, ISP_LOGINFO, "Chan %d %s (PortID 0x%06x)",

Modified: stable/11/sys/dev/isp/ispmbox.h
==============================================================================
--- stable/11/sys/dev/isp/ispmbox.h	Wed May 10 18:33:40 2017	(r318147)
+++ stable/11/sys/dev/isp/ispmbox.h	Wed May 10 18:59:18 2017	(r318148)
@@ -1421,6 +1421,10 @@ typedef struct {
 /*
  * Port Database Changed Async Event information for 24XX cards
  */
+/* N-Port Handle */
+#define PDB24XX_AE_GLOBAL	0xFFFF
+
+/* Reason Codes */
 #define	PDB24XX_AE_OK		0x00
 #define	PDB24XX_AE_IMPL_LOGO_1	0x01
 #define	PDB24XX_AE_IMPL_LOGO_2	0x02
@@ -1440,7 +1444,7 @@ typedef struct {
 #define	PDB24XX_AE_FLOGI_TIMO	0x10
 #define	PDB24XX_AE_ABX_LOGO	0x11
 #define	PDB24XX_AE_PLOGI_DONE	0x12
-#define	PDB24XX_AE_PRLI_DONJE	0x13
+#define	PDB24XX_AE_PRLI_DONE	0x13
 #define	PDB24XX_AE_OPN_1	0x14
 #define	PDB24XX_AE_OPN_2	0x15
 #define	PDB24XX_AE_TXERR	0x16

Modified: stable/11/sys/dev/isp/ispvar.h
==============================================================================
--- stable/11/sys/dev/isp/ispvar.h	Wed May 10 18:33:40 2017	(r318147)
+++ stable/11/sys/dev/isp/ispvar.h	Wed May 10 18:59:18 2017	(r318148)
@@ -502,6 +502,10 @@ typedef struct {
 
 #define TOPO_IS_FABRIC(x)	((x) == TOPO_FL_PORT || (x) == TOPO_F_PORT)
 
+#define FCP_AL_DA_ALL		0xFF
+#define FCP_AL_PA(fcp) ((uint8_t)(fcp->isp_portid))
+#define FCP_IS_DEST_ALPD(fcp, alpd) (FCP_AL_PA((fcp)) == FCP_AL_DA_ALL || FCP_AL_PA((fcp)) == alpd)
+
 /*
  * Soft Structure per host adapter
  */



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