]> xenbits.xensource.com Git - people/liuw/freebsd.git/commitdiff
Formalize/unify chip (re-)inits.
authormav <mav@FreeBSD.org>
Sun, 25 Oct 2015 10:49:05 +0000 (10:49 +0000)
committermav <mav@FreeBSD.org>
Sun, 25 Oct 2015 10:49:05 +0000 (10:49 +0000)
sys/dev/isp/isp.c
sys/dev/isp/isp_freebsd.c
sys/dev/isp/isp_pci.c
sys/dev/isp/isp_sbus.c

index 2bd85a3fbee3bf7904cecf915e9e8c3d24606756..f8da1c97686caa8a0489ea1129821704c3881e1d 100644 (file)
@@ -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
@@ -4348,16 +4350,6 @@ isp_start(XS_T *xs)
        XS_INITERR(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,
@@ -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_defaults)
 {
        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_defaults)
        }
 
        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)) {
                        /*
index 3115787dee02990b2332fa9ec066714137fdffca..c78b3555ccebeb784d02404276fc46ff5afc64d1 100644 (file)
@@ -4029,19 +4029,6 @@ isp_action(struct cam_sim *sim, union ccb *ccb)
        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);
index 9f8c82dc41d08e3387454d180ad7c1ec89b6bdf7..cbc1994fd7a0d1de6265188343968f8ef908e0e0 100644 (file)
@@ -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);
index 14b3941676fcd99797cff972c5fe24332460ce8b..cebfe8b766e022493d53937c22fdb1f9bc4ff81f 100644 (file)
@@ -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);