diff --git a/qla2x00t/qla2x00-target/qla2x00t.c b/qla2x00t/qla2x00-target/qla2x00t.c index 848413564..a92440611 100644 --- a/qla2x00t/qla2x00-target/qla2x00t.c +++ b/qla2x00t/qla2x00-target/qla2x00t.c @@ -2679,6 +2679,31 @@ out_unlock_free_unmap: goto out; } +/* + * Convert sense buffer (byte array) to little endian format as required by + * qla24xx firmware. + */ +static void q24_copy_sense_buffer_to_ctio(ctio7_status1_entry_t *ctio, + uint8_t *sense_buf, unsigned int sense_buf_len) +{ + uint32_t *src = (void *)sense_buf; + uint32_t *end = (void *)sense_buf + sense_buf_len; + uint8_t *p; + __be32 *dst = (void *)ctio->sense_data; + + /* + * The sense buffer allocated by scst_alloc_sense() is zero-filled and + * has a length that is a multiple of four. This means that it is safe + * to access the bytes after the end of the sense buffer up to a + * boundary that is a multiple of four. + */ + for (p = (uint8_t *)end; ((uintptr_t)p & 3) != 0; p++) + WARN_ONCE(*p != 0, "sense_buf[%zd] = %d\n", p - sense_buf, *p); + + for ( ; src < end; src++) + *dst++ = cpu_to_be32(*src); +} + static inline int q2t_need_explicit_conf(scsi_qla_host_t *ha, struct q2t_cmd *cmd, int sending_sense) { @@ -2914,7 +2939,6 @@ static void q24_init_ctio_ret_entry(ctio7_status0_entry_t *ctio, ctio->residual = cpu_to_le32(prm->residual); ctio->scsi_status = cpu_to_le16(prm->rq_result); if (scst_sense_valid(prm->sense_buffer)) { - int i; ctio1 = (ctio7_status1_entry_t *)ctio; if (q2t_need_explicit_conf(prm->tgt->ha, prm->cmd, 1)) { ctio1->flags |= cpu_to_le16( @@ -2925,20 +2949,8 @@ static void q24_init_ctio_ret_entry(ctio7_status0_entry_t *ctio, ctio1->flags |= cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_1); ctio1->scsi_status |= cpu_to_le16(SS_SENSE_LEN_VALID); ctio1->sense_length = cpu_to_le16(prm->sense_buffer_len); - for (i = 0; i < prm->sense_buffer_len/4; i++) - ((uint32_t *)ctio1->sense_data)[i] = - cpu_to_be32(((uint32_t *)prm->sense_buffer)[i]); -#if 0 - if (unlikely((prm->sense_buffer_len % 4) != 0)) { - static int q; - if (q < 10) { - PRINT_INFO("qla2x00t(%ld): %d bytes of sense " - "lost", prm->tgt->ha->instance, - prm->sense_buffer_len % 4); - q++; - } - } -#endif + q24_copy_sense_buffer_to_ctio(ctio1, prm->sense_buffer, + prm->sense_buffer_len); } else { ctio1 = (ctio7_status1_entry_t *)ctio; ctio1->flags &= ~cpu_to_le16(CTIO7_FLAGS_STATUS_MODE_0);