#include "device.h"
 #include "ioasm.h"
 
+/*
+ * Helper function called from interrupt context to decide whether an
+ * operation should be tried again.
+ */
+static int __ccw_device_should_retry(struct scsw *scsw)
+{
+       /* CC is only valid if start function bit is set. */
+       if ((scsw->fctl & SCSW_FCTL_START_FUNC) && scsw->cc == 1)
+               return 1;
+       /* No more activity. For sense and set PGID we stubbornly try again. */
+       if (!scsw->actl)
+               return 1;
+       return 0;
+}
+
 /*
  * Start Sense Path Group ID helper function. Used in ccw_device_recog
  * and ccw_device_sense_pgid.
        int ret;
 
        irb = (struct irb *) __LC_IRB;
-       /* Retry sense pgid for cc=1. */
+
        if (irb->scsw.stctl ==
            (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
-               if (irb->scsw.cc == 1) {
+               if (__ccw_device_should_retry(&irb->scsw)) {
                        ret = __ccw_device_sense_pgid_start(cdev);
                        if (ret && ret != -EBUSY)
                                ccw_device_sense_pgid_done(cdev, ret);
        int ret;
 
        irb = (struct irb *) __LC_IRB;
-       /* Retry set pgid for cc=1. */
+
        if (irb->scsw.stctl ==
            (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
-               if (irb->scsw.cc == 1)
+               if (__ccw_device_should_retry(&irb->scsw))
                        __ccw_device_verify_start(cdev);
                return;
        }
        int ret;
 
        irb = (struct irb *) __LC_IRB;
-       /* Retry set pgid for cc=1. */
+
        if (irb->scsw.stctl ==
            (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
-               if (irb->scsw.cc == 1)
+               if (__ccw_device_should_retry(&irb->scsw))
                        __ccw_device_disband_start(cdev);
                return;
        }