Message ID | 20250128142250.163901-6-Kai.Makisara@kolumbus.fi (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | scsi: scsi_debug: Add more tape support | expand |
Reviewed-by: John Meneghini <jmeneghi@redhat.com> Tested-by: John Meneghini <jmeneghi@redhat.com> I've tested out these patches my existing tests and found no regressions. I'll work to add a compression mode test to my tape_tests in the future. On 1/28/25 9:22 AM, Kai Mäkisara wrote: > 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> > --- > drivers/scsi/scsi_debug.c | 33 +++++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c > index 912b1c6cf92d..ceacf38cee71 100644 > --- a/drivers/scsi/scsi_debug.c > +++ b/drivers/scsi/scsi_debug.c > @@ -405,6 +405,7 @@ struct sdebug_dev_info { > unsigned int tape_blksize; > unsigned int tape_density; > unsigned char tape_partition; > + 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 > > @@ -2979,6 +2994,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; > @@ -3132,6 +3153,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, > @@ -3147,6 +3176,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)
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 912b1c6cf92d..ceacf38cee71 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -405,6 +405,7 @@ struct sdebug_dev_info { unsigned int tape_blksize; unsigned int tape_density; unsigned char tape_partition; + 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 @@ -2979,6 +2994,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; @@ -3132,6 +3153,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, @@ -3147,6 +3176,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)
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> --- drivers/scsi/scsi_debug.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)