]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
scsi: scsi_debug: Add compression mode page for tapes
authorKai Mäkisara <Kai.Makisara@kolumbus.fi>
Thu, 13 Feb 2025 09:26:34 +0000 (11:26 +0200)
committerMartin K. Petersen <martin.petersen@oracle.com>
Mon, 24 Feb 2025 03:01:03 +0000 (22:01 -0500)
Add support for compression mode page. The compression status
is saved and returned. No UA is generated.

Signed-off-by: Kai Mäkisara <Kai.Makisara@kolumbus.fi>
Link: https://lore.kernel.org/r/20250213092636.2510-6-Kai.Makisara@kolumbus.fi
Reviewed-by: John Meneghini <jmeneghi@redhat.com>
Tested-by: John Meneghini <jmeneghi@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/scsi_debug.c

index 790d0fe65235a0d6cf1b5d12291b2b3cb7eb4cd8..394a830327c9c70f6d5e38802ce9ca29a9762853 100644 (file)
@@ -405,6 +405,7 @@ struct sdebug_dev_info {
        unsigned int tape_density;
        unsigned char tape_partition;
        unsigned char tape_nbr_partitions;
+       unsigned char tape_dce;
        unsigned int tape_location[TAPE_MAX_PARTITIONS];
        unsigned int tape_eop[TAPE_MAX_PARTITIONS];
        struct tape_block *tape_blocks[TAPE_MAX_PARTITIONS];
@@ -2843,6 +2844,20 @@ static int resp_partition_m_pg(unsigned char *p, int pcontrol, int target)
        return sizeof(partition_pg);
 }
 
+static int resp_compression_m_pg(unsigned char *p, int pcontrol, int target,
+       unsigned char dce)
+{      /* Compression page for mode_sense (tape) */
+       unsigned char compression_pg[] = {0x0f, 14, 0x40, 0, 0, 0, 0, 0,
+               0, 0, 0, 0, 00, 00};
+
+       memcpy(p, compression_pg, sizeof(compression_pg));
+       if (dce)
+               p[2] |= 0x80;
+       if (pcontrol == 1)
+               memset(p + 2, 0, sizeof(compression_pg) - 2);
+       return sizeof(compression_pg);
+}
+
 /* PAGE_SIZE is more than necessary but provides room for future expansion. */
 #define SDEBUG_MAX_MSENSE_SZ PAGE_SIZE
 
@@ -2983,6 +2998,12 @@ static int resp_mode_sense(struct scsi_cmnd *scp,
                }
                offset += len;
                break;
+       case 0xf:       /* Compression Mode Page (tape) */
+               if (!is_tape)
+                       goto bad_pcode;
+               len += resp_compression_m_pg(ap, pcontrol, target, devip->tape_dce);
+               offset += len;
+               break;
        case 0x11:      /* Partition Mode Page (tape) */
                if (!is_tape)
                        goto bad_pcode;
@@ -3143,6 +3164,14 @@ static int resp_mode_select(struct scsi_cmnd *scp,
                        goto set_mode_changed_ua;
                }
                break;
+       case 0xf:       /* Compression mode page */
+               if (sdebug_ptype != TYPE_TAPE)
+                       goto bad_pcode;
+               if ((arr[off + 2] & 0x40) != 0) {
+                       devip->tape_dce = (arr[off + 2] & 0x80) != 0;
+                       return 0;
+               }
+               break;
        case 0x1c:      /* Informational Exceptions Mode page */
                if (iec_m_pg[1] == arr[off + 1]) {
                        memcpy(iec_m_pg + 2, arr + off + 2,
@@ -3158,6 +3187,10 @@ static int resp_mode_select(struct scsi_cmnd *scp,
 set_mode_changed_ua:
        set_bit(SDEBUG_UA_MODE_CHANGED, devip->uas_bm);
        return 0;
+
+bad_pcode:
+       mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, 5);
+       return check_condition_result;
 }
 
 static int resp_temp_l_pg(unsigned char *arr)