Message ID | 20231130013322.175290-10-bvanassche@acm.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Pass data lifetime information to SCSI disk devices | expand |
On 30.11.23 02:34, Bart Van Assche wrote: > +/* SBC-5 IO advice hints group descriptor */ > +struct scsi_io_group_descriptor { > +#if defined(__BIG_ENDIAN) > + u8 io_advice_hints_mode: 2; > + u8 reserved1: 3; > + u8 st_enble: 1; > + u8 cs_enble: 1; > + u8 ic_enable: 1; > +#elif defined(__LITTLE_ENDIAN) > + u8 ic_enable: 1; > + u8 cs_enble: 1; > + u8 st_enble: 1; > + u8 reserved1: 3; > + u8 io_advice_hints_mode: 2; > +#else > +#error > +#endif > + u8 reserved2[3]; > + /* Logical block markup descriptor */ > +#if defined(__BIG_ENDIAN) > + u8 acdlu: 1; > + u8 reserved3: 1; > + u8 rlbsr: 2; > + u8 lbm_descriptor_type: 4; > +#elif defined(__LITTLE_ENDIAN) > + u8 lbm_descriptor_type: 4; > + u8 rlbsr: 2; > + u8 reserved3: 1; > + u8 acdlu: 1; > +#else > +#error > +#endif > + u8 params[2]; > + u8 reserved4; > + u8 reserved5[8]; > +}; > + > +static_assert(sizeof(struct scsi_io_group_descriptor) == 16); Hi Bart, Have you considered using GENMASK() and FILED_GET() for this? All the ifdefs make the header rather ugly.
On 11/30/23 05:19, Johannes Thumshirn wrote: > On 30.11.23 02:34, Bart Van Assche wrote: >> +/* SBC-5 IO advice hints group descriptor */ >> +struct scsi_io_group_descriptor { >> +#if defined(__BIG_ENDIAN) >> + u8 io_advice_hints_mode: 2; >> + u8 reserved1: 3; >> + u8 st_enble: 1; >> + u8 cs_enble: 1; >> + u8 ic_enable: 1; >> +#elif defined(__LITTLE_ENDIAN) >> + u8 ic_enable: 1; >> + u8 cs_enble: 1; >> + u8 st_enble: 1; >> + u8 reserved1: 3; >> + u8 io_advice_hints_mode: 2; >> +#else >> +#error >> +#endif >> + u8 reserved2[3]; >> + /* Logical block markup descriptor */ >> +#if defined(__BIG_ENDIAN) >> + u8 acdlu: 1; >> + u8 reserved3: 1; >> + u8 rlbsr: 2; >> + u8 lbm_descriptor_type: 4; >> +#elif defined(__LITTLE_ENDIAN) >> + u8 lbm_descriptor_type: 4; >> + u8 rlbsr: 2; >> + u8 reserved3: 1; >> + u8 acdlu: 1; >> +#else >> +#error >> +#endif >> + u8 params[2]; >> + u8 reserved4; >> + u8 reserved5[8]; >> +}; >> + >> +static_assert(sizeof(struct scsi_io_group_descriptor) == 16); > > Have you considered using GENMASK() and FILED_GET() for this? All the > ifdefs make the header rather ugly. Hi Johannes, When using bitfields, there are #ifdefs in the data structure definitions but it is easy to write code that accesses the bitfields. When using FIELD_GET(), the data structure definitions have no ifdefs but the code that reads bitfields becomes harder to verify. The code for setting bitfield values would have to use FIELD_PREP() and hence would become more complex. An example of code that sets bitfields is the definition of the gr_m_pg data structure in patch 15/17 of this series. It would become more complicated if FIELD_PREP() would have to be used in the definition of that data structure. Thanks, Bart.
diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h index 07d65c1f59db..9ee4983c23b4 100644 --- a/include/scsi/scsi_proto.h +++ b/include/scsi/scsi_proto.h @@ -10,6 +10,7 @@ #ifndef _SCSI_PROTO_H_ #define _SCSI_PROTO_H_ +#include <linux/build_bug.h> #include <linux/types.h> /* @@ -126,6 +127,7 @@ #define SAI_READ_CAPACITY_16 0x10 #define SAI_GET_LBA_STATUS 0x12 #define SAI_REPORT_REFERRALS 0x13 +#define SAI_GET_STREAM_STATUS 0x16 /* values for maintenance in */ #define MI_REPORT_IDENTIFYING_INFORMATION 0x05 #define MI_REPORT_TARGET_PGS 0x0a @@ -275,6 +277,79 @@ struct scsi_lun { __u8 scsi_lun[8]; }; +/* SBC-5 IO advice hints group descriptor */ +struct scsi_io_group_descriptor { +#if defined(__BIG_ENDIAN) + u8 io_advice_hints_mode: 2; + u8 reserved1: 3; + u8 st_enble: 1; + u8 cs_enble: 1; + u8 ic_enable: 1; +#elif defined(__LITTLE_ENDIAN) + u8 ic_enable: 1; + u8 cs_enble: 1; + u8 st_enble: 1; + u8 reserved1: 3; + u8 io_advice_hints_mode: 2; +#else +#error +#endif + u8 reserved2[3]; + /* Logical block markup descriptor */ +#if defined(__BIG_ENDIAN) + u8 acdlu: 1; + u8 reserved3: 1; + u8 rlbsr: 2; + u8 lbm_descriptor_type: 4; +#elif defined(__LITTLE_ENDIAN) + u8 lbm_descriptor_type: 4; + u8 rlbsr: 2; + u8 reserved3: 1; + u8 acdlu: 1; +#else +#error +#endif + u8 params[2]; + u8 reserved4; + u8 reserved5[8]; +}; + +static_assert(sizeof(struct scsi_io_group_descriptor) == 16); + +struct scsi_stream_status { +#if defined(__BIG_ENDIAN) + u16 perm: 1; + u16 reserved1: 15; +#elif defined(__LITTLE_ENDIAN) + u16 reserved1: 15; + u16 perm: 1; +#else +#error +#endif + __be16 stream_identifier; +#if defined(__BIG_ENDIAN) + u8 reserved2: 2; + u8 rel_lifetime: 6; +#elif defined(__LITTLE_ENDIAN) + u8 rel_lifetime: 6; + u8 reserved2: 2; +#else +#error +#endif + u8 reserved3[3]; +}; + +static_assert(sizeof(struct scsi_stream_status) == 8); + +struct scsi_stream_status_header { + __be32 len; /* length in bytes of stream_status[] array. */ + u16 reserved; + u16 number_of_open_streams; + DECLARE_FLEX_ARRAY(struct scsi_stream_status, stream_status); +}; + +static_assert(sizeof(struct scsi_stream_status_header) == 8); + /* SPC asymmetric access states */ #define SCSI_ACCESS_STATE_OPTIMAL 0x00 #define SCSI_ACCESS_STATE_ACTIVE 0x01
Prepare for adding code that will query the I/O advice hints group descriptors and for adding code that will retrieve the stream status. Cc: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Bart Van Assche <bvanassche@acm.org> --- include/scsi/scsi_proto.h | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)