]> Pileus Git - ~andy/linux/blobdiff - drivers/scsi/qla4xxx/ql4_isr.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394...
[~andy/linux] / drivers / scsi / qla4xxx / ql4_isr.c
index 946e22b1e4b81724122ee2f606d130974523b44e..0f029d0d73150e17881cec0f98575134d22438e8 100644 (file)
@@ -93,9 +93,29 @@ static void qla4xxx_status_entry(struct scsi_qla_host *ha,
                        break;
                }
 
-               if (sts_entry->iscsiFlags &
-                   (ISCSI_FLAG_RESIDUAL_OVER|ISCSI_FLAG_RESIDUAL_UNDER))
-                       cmd->resid = residual;
+               if (sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) {
+                       cmd->result = DID_ERROR << 16;
+                       break;
+               }
+
+               if (sts_entry->iscsiFlags &ISCSI_FLAG_RESIDUAL_UNDER) {
+                       scsi_set_resid(cmd, residual);
+                       if (!scsi_status && ((scsi_bufflen(cmd) - residual) <
+                               cmd->underflow)) {
+
+                               cmd->result = DID_ERROR << 16;
+
+                               DEBUG2(printk("scsi%ld:%d:%d:%d: %s: "
+                                       "Mid-layer Data underrun0, "
+                                       "xferlen = 0x%x, "
+                                       "residual = 0x%x\n", ha->host_no,
+                                       cmd->device->channel,
+                                       cmd->device->id,
+                                       cmd->device->lun, __func__,
+                                       scsi_bufflen(cmd), residual));
+                               break;
+                       }
+               }
 
                cmd->result = DID_OK << 16 | scsi_status;
 
@@ -103,15 +123,14 @@ static void qla4xxx_status_entry(struct scsi_qla_host *ha,
                        break;
 
                /* Copy Sense Data into sense buffer. */
-               memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
+               memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
 
                sensebytecnt = le16_to_cpu(sts_entry->senseDataByteCnt);
                if (sensebytecnt == 0)
                        break;
 
                memcpy(cmd->sense_buffer, sts_entry->senseData,
-                      min(sensebytecnt,
-                          (uint16_t) sizeof(cmd->sense_buffer)));
+                      min_t(uint16_t, sensebytecnt, SCSI_SENSE_BUFFERSIZE));
 
                DEBUG2(printk("scsi%ld:%d:%d:%d: %s: sense key = %x, "
                              "ASC/ASCQ = %02x/%02x\n", ha->host_no,
@@ -164,7 +183,8 @@ static void qla4xxx_status_entry(struct scsi_qla_host *ha,
 
        case SCS_DATA_UNDERRUN:
        case SCS_DATA_OVERRUN:
-               if (sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) {
+               if ((sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) ||
+                       (sts_entry->completionStatus == SCS_DATA_OVERRUN)) {
                        DEBUG2(printk("scsi%ld:%d:%d:%d: %s: " "Data overrun, "
                                      "residual = 0x%x\n", ha->host_no,
                                      cmd->device->channel, cmd->device->id,
@@ -174,21 +194,7 @@ static void qla4xxx_status_entry(struct scsi_qla_host *ha,
                        break;
                }
 
-               if ((sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_UNDER) == 0) {
-                       /*
-                        * Firmware detected a SCSI transport underrun
-                        * condition
-                        */
-                       cmd->resid = residual;
-                       DEBUG2(printk("scsi%ld:%d:%d:%d: %s: UNDERRUN status "
-                                     "detected, xferlen = 0x%x, residual = "
-                                     "0x%x\n",
-                                     ha->host_no, cmd->device->channel,
-                                     cmd->device->id,
-                                     cmd->device->lun, __func__,
-                                     cmd->request_bufflen,
-                                     residual));
-               }
+               scsi_set_resid(cmd, residual);
 
                /*
                 * If there is scsi_status, it takes precedense over
@@ -201,8 +207,7 @@ static void qla4xxx_status_entry(struct scsi_qla_host *ha,
                                break;
 
                        /* Copy Sense Data into sense buffer. */
-                       memset(cmd->sense_buffer, 0,
-                              sizeof(cmd->sense_buffer));
+                       memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
 
                        sensebytecnt =
                                le16_to_cpu(sts_entry->senseDataByteCnt);
@@ -210,8 +215,7 @@ static void qla4xxx_status_entry(struct scsi_qla_host *ha,
                                break;
 
                        memcpy(cmd->sense_buffer, sts_entry->senseData,
-                              min(sensebytecnt,
-                                  (uint16_t) sizeof(cmd->sense_buffer)));
+                              min_t(uint16_t, sensebytecnt, SCSI_SENSE_BUFFERSIZE));
 
                        DEBUG2(printk("scsi%ld:%d:%d:%d: %s: sense key = %x, "
                                      "ASC/ASCQ = %02x/%02x\n", ha->host_no,
@@ -230,7 +234,7 @@ static void qla4xxx_status_entry(struct scsi_qla_host *ha,
                        if ((sts_entry->iscsiFlags &
                             ISCSI_FLAG_RESIDUAL_UNDER) == 0) {
                                cmd->result = DID_BUS_BUSY << 16;
-                       } else if ((cmd->request_bufflen - residual) <
+                       } else if ((scsi_bufflen(cmd) - residual) <
                                   cmd->underflow) {
                                /*
                                 * Handle mid-layer underflow???
@@ -245,13 +249,13 @@ static void qla4xxx_status_entry(struct scsi_qla_host *ha,
                                 * will return DID_ERROR.
                                 */
                                DEBUG2(printk("scsi%ld:%d:%d:%d: %s: "
-                                             "Mid-layer Data underrun, "
-                                             "xferlen = 0x%x, "
-                                             "residual = 0x%x\n", ha->host_no,
-                                             cmd->device->channel,
-                                             cmd->device->id,
-                                             cmd->device->lun, __func__,
-                                             cmd->request_bufflen, residual));
+                                       "Mid-layer Data underrun1, "
+                                       "xferlen = 0x%x, "
+                                       "residual = 0x%x\n", ha->host_no,
+                                       cmd->device->channel,
+                                       cmd->device->id,
+                                       cmd->device->lun, __func__,
+                                       scsi_bufflen(cmd), residual));
 
                                cmd->result = DID_ERROR << 16;
                        } else {