Author: mav
Date: Sun Oct 25 10:49:05 2015
New Revision: 289930
URL: https://svnweb.freebsd.org/changeset/base/289930

Log:
  Formalize/unify chip (re-)inits.

Modified:
  head/sys/dev/isp/isp.c
  head/sys/dev/isp/isp_freebsd.c
  head/sys/dev/isp/isp_pci.c
  head/sys/dev/isp/isp_sbus.c

Modified: head/sys/dev/isp/isp.c
==============================================================================
--- head/sys/dev/isp/isp.c      Sun Oct 25 09:16:20 2015        (r289929)
+++ head/sys/dev/isp/isp.c      Sun Oct 25 10:49:05 2015        (r289930)
@@ -1368,6 +1368,8 @@ isp_scsi_init(ispsoftc_t *isp)
        sdparam *sdp_chan0, *sdp_chan1;
        mbreg_t mbs;
 
+       isp->isp_state = ISP_INITSTATE;
+
        sdp_chan0 = SDPARAM(isp, 0);
        sdp_chan1 = sdp_chan0;
        if (IS_DUALBUS(isp)) {
@@ -1543,7 +1545,7 @@ isp_scsi_init(ispsoftc_t *isp)
                }
        }
 
-       isp->isp_state = ISP_INITSTATE;
+       isp->isp_state = ISP_RUNSTATE;
 }
 
 static void
@@ -1673,11 +1675,10 @@ isp_fibre_init(ispsoftc_t *isp)
         * We only support one channel on non-24XX cards
         */
        fcp = FCPARAM(isp, 0);
-       if (fcp->role == ISP_ROLE_NONE) {
-               isp->isp_state = ISP_INITSTATE;
+       if (fcp->role == ISP_ROLE_NONE)
                return;
-       }
 
+       isp->isp_state = ISP_INITSTATE;
        ISP_MEMZERO(icbp, sizeof (*icbp));
        icbp->icb_version = ICB_VERSION1;
        icbp->icb_fwoptions = fcp->isp_fwoptions;
@@ -1978,7 +1979,7 @@ isp_fibre_init(ispsoftc_t *isp)
        /*
         * Whatever happens, we're now committed to being here.
         */
-       isp->isp_state = ISP_INITSTATE;
+       isp->isp_state = ISP_RUNSTATE;
 }
 
 static void
@@ -2001,10 +2002,11 @@ isp_fibre_init_2400(ispsoftc_t *isp)
        }
        if (chan == isp->isp_nchan) {
                isp_prt(isp, ISP_LOG_WARN1, "all %d channels with role 'none'", 
chan);
-               isp->isp_state = ISP_INITSTATE;
                return;
        }
 
+       isp->isp_state = ISP_INITSTATE;
+
        /*
         * Start with channel 0.
         */
@@ -2285,7 +2287,7 @@ isp_fibre_init_2400(ispsoftc_t *isp)
        /*
         * Whatever happens, we're now committed to being here.
         */
-       isp->isp_state = ISP_INITSTATE;
+       isp->isp_state = ISP_RUNSTATE;
 }
 
 static void
@@ -4349,16 +4351,6 @@ isp_start(XS_T *xs)
        isp = XS_ISP(xs);
 
        /*
-        * Now make sure we're running.
-        */
-
-       if (isp->isp_state != ISP_RUNSTATE) {
-               isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
-               XS_SETERR(xs, HBA_BOTCH);
-               return (CMD_COMPLETE);
-       }
-
-       /*
         * Check command CDB length, etc.. We really are limited to 16 bytes
         * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
         * but probably only if we're running fairly new firmware (we'll
@@ -4387,6 +4379,12 @@ isp_start(XS_T *xs)
                        return (CMD_COMPLETE);
                }
 
+               if (isp->isp_state != ISP_RUNSTATE) {
+                       isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
+                       XS_SETERR(xs, HBA_BOTCH);
+                       return (CMD_COMPLETE);
+               }
+
                /*
                 * Try again later.
                 */
@@ -4423,6 +4421,13 @@ isp_start(XS_T *xs)
                        XS_SETERR(xs, HBA_SELTIMEOUT);
                        return (CMD_COMPLETE);
                }
+
+               if (isp->isp_state != ISP_RUNSTATE) {
+                       isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
+                       XS_SETERR(xs, HBA_BOTCH);
+                       return (CMD_COMPLETE);
+               }
+
                if (sdp->update) {
                        isp_spi_update(isp, XS_CHANNEL(xs));
                }
@@ -7915,7 +7920,8 @@ isp_reinit(ispsoftc_t *isp, int do_load_
 {
        int i, res = 0;
 
-       isp_reset(isp, do_load_defaults);
+       if (isp->isp_state != ISP_RESETSTATE)
+               isp_reset(isp, do_load_defaults);
        if (isp->isp_state != ISP_RESETSTATE) {
                res = EIO;
                isp_prt(isp, ISP_LOGERR, "%s: cannot reset card", __func__);
@@ -7924,15 +7930,10 @@ isp_reinit(ispsoftc_t *isp, int do_load_
        }
 
        isp_init(isp);
-       if (isp->isp_state == ISP_INITSTATE) {
-               isp->isp_state = ISP_RUNSTATE;
-       }
-
-       if (isp->isp_state != ISP_RUNSTATE) {
+       if (isp->isp_state > ISP_RESETSTATE &&
+           isp->isp_state != ISP_RUNSTATE) {
                res = EIO;
-#ifndef        ISP_TARGET_MODE
-               isp_prt(isp, ISP_LOGWARN, "%s: not at runstate", __func__);
-#endif
+               isp_prt(isp, ISP_LOGERR, "%s: cannot init card", __func__);
                ISP_DISABLE_INTS(isp);
                if (IS_FC(isp)) {
                        /*

Modified: head/sys/dev/isp/isp_freebsd.c
==============================================================================
--- head/sys/dev/isp/isp_freebsd.c      Sun Oct 25 09:16:20 2015        
(r289929)
+++ head/sys/dev/isp/isp_freebsd.c      Sun Oct 25 10:49:05 2015        
(r289930)
@@ -4029,19 +4029,6 @@ isp_action(struct cam_sim *sim, union cc
        isp_prt(isp, ISP_LOGDEBUG2, "isp_action code %x", ccb->ccb_h.func_code);
        ISP_PCMD(ccb) = NULL;
 
-       if (isp->isp_state != ISP_RUNSTATE && ccb->ccb_h.func_code == 
XPT_SCSI_IO) {
-               isp_init(isp);
-               if (isp->isp_state != ISP_INITSTATE) {
-                       /*
-                        * Lie. Say it was a selection timeout.
-                        */
-                       ccb->ccb_h.status = CAM_SEL_TIMEOUT;
-                       isp_done((struct ccb_scsiio *) ccb);
-                       return;
-               }
-               isp->isp_state = ISP_RUNSTATE;
-       }
-
        switch (ccb->ccb_h.func_code) {
        case XPT_SCSI_IO:       /* Execute the requested I/O operation */
                bus = XS_CHANNEL(ccb);

Modified: head/sys/dev/isp/isp_pci.c
==============================================================================
--- head/sys/dev/isp/isp_pci.c  Sun Oct 25 09:16:20 2015        (r289929)
+++ head/sys/dev/isp/isp_pci.c  Sun Oct 25 10:49:05 2015        (r289930)
@@ -991,15 +991,10 @@ isp_pci_attach(device_t dev)
         * Make sure we're in reset state.
         */
        ISP_LOCK(isp);
-       isp_reset(isp, 1);
-       if (isp->isp_state != ISP_RESETSTATE) {
+       if (isp_reinit(isp, 1) != 0) {
                ISP_UNLOCK(isp);
                goto bad;
        }
-       isp_init(isp);
-       if (isp->isp_state == ISP_INITSTATE) {
-               isp->isp_state = ISP_RUNSTATE;
-       }
        ISP_UNLOCK(isp);
        if (isp_attach(isp)) {
                ISP_LOCK(isp);

Modified: head/sys/dev/isp/isp_sbus.c
==============================================================================
--- head/sys/dev/isp/isp_sbus.c Sun Oct 25 09:16:20 2015        (r289929)
+++ head/sys/dev/isp/isp_sbus.c Sun Oct 25 10:49:05 2015        (r289930)
@@ -313,16 +313,11 @@ isp_sbus_attach(device_t dev)
         * Make sure we're in reset state.
         */
        ISP_LOCK(isp);
-       isp_reset(isp, 1);
-       if (isp->isp_state != ISP_RESETSTATE) {
+       if (isp_reinit(isp, 1) != 0) {
                isp_uninit(isp);
                ISP_UNLOCK(isp);
                goto bad;
        }
-       isp_init(isp);
-       if (isp->isp_state == ISP_INITSTATE) {
-               isp->isp_state = ISP_RUNSTATE;
-       }
        ISP_UNLOCK(isp);
        if (isp_attach(isp)) {
                ISP_LOCK(isp);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to