Skip to content

Commit 4977c0f

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: scsi_proto: Add structures and constants related to I/O groups and streams
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 <[email protected]> Signed-off-by: Bart Van Assche <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 96b171d commit 4977c0f

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed

drivers/scsi/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ config SCSI_SCAN_ASYNC
232232
Note that this setting also affects whether resuming from
233233
system suspend will be performed asynchronously.
234234

235+
config SCSI_PROTO_TEST
236+
tristate "scsi_proto.h unit tests" if !KUNIT_ALL_TESTS
237+
depends on SCSI && KUNIT
238+
default KUNIT_ALL_TESTS
239+
235240
menu "SCSI Transports"
236241
depends on SCSI
237242

drivers/scsi/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ obj-$(CONFIG_SCSI_COMMON) += scsi_common.o
2424

2525
obj-$(CONFIG_RAID_ATTRS) += raid_class.o
2626

27+
obj-$(CONFIG_SCSI_PROTO_TEST) += scsi_proto_test.o
28+
2729
# --- NOTE ORDERING HERE ---
2830
# For kernel non-modular link, transport attributes need to
2931
# be initialised before drivers

drivers/scsi/scsi_proto_test.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright 2023 Google LLC
4+
*/
5+
#include <kunit/test.h>
6+
#include <asm-generic/unaligned.h>
7+
#include <scsi/scsi_proto.h>
8+
9+
static void test_scsi_proto(struct kunit *test)
10+
{
11+
static const union {
12+
struct scsi_io_group_descriptor desc;
13+
u8 arr[sizeof(struct scsi_io_group_descriptor)];
14+
} d = { .arr = { 0x45, 0, 0, 0, 0xb0, 0xe4, 0xe3 } };
15+
KUNIT_EXPECT_EQ(test, d.desc.io_advice_hints_mode + 0, 1);
16+
KUNIT_EXPECT_EQ(test, d.desc.st_enble + 0, 1);
17+
KUNIT_EXPECT_EQ(test, d.desc.cs_enble + 0, 0);
18+
KUNIT_EXPECT_EQ(test, d.desc.ic_enable + 0, 1);
19+
KUNIT_EXPECT_EQ(test, d.desc.acdlu + 0, 1);
20+
KUNIT_EXPECT_EQ(test, d.desc.rlbsr + 0, 3);
21+
KUNIT_EXPECT_EQ(test, d.desc.lbm_descriptor_type + 0, 0);
22+
KUNIT_EXPECT_EQ(test, d.desc.params[0] + 0, 0xe4);
23+
KUNIT_EXPECT_EQ(test, d.desc.params[1] + 0, 0xe3);
24+
25+
static const union {
26+
struct scsi_stream_status s;
27+
u8 arr[sizeof(struct scsi_stream_status)];
28+
} ss = { .arr = { 0x80, 0, 0x12, 0x34, 0x3f } };
29+
KUNIT_EXPECT_EQ(test, ss.s.perm + 0, 1);
30+
KUNIT_EXPECT_EQ(test, get_unaligned_be16(&ss.s.stream_identifier),
31+
0x1234);
32+
KUNIT_EXPECT_EQ(test, ss.s.rel_lifetime + 0, 0x3f);
33+
34+
static const union {
35+
struct scsi_stream_status_header h;
36+
u8 arr[sizeof(struct scsi_stream_status_header)];
37+
} sh = { .arr = { 1, 2, 3, 4, 0, 0, 5, 6 } };
38+
KUNIT_EXPECT_EQ(test, get_unaligned_be32(&sh.h.len), 0x1020304);
39+
KUNIT_EXPECT_EQ(test, get_unaligned_be16(&sh.h.number_of_open_streams),
40+
0x506);
41+
}
42+
43+
static struct kunit_case scsi_proto_test_cases[] = {
44+
KUNIT_CASE(test_scsi_proto),
45+
{}
46+
};
47+
48+
static struct kunit_suite scsi_proto_test_suite = {
49+
.name = "scsi_proto",
50+
.test_cases = scsi_proto_test_cases,
51+
};
52+
kunit_test_suite(scsi_proto_test_suite);
53+
54+
MODULE_DESCRIPTION("<scsi/scsi_proto.h> unit tests");
55+
MODULE_AUTHOR("Bart Van Assche");
56+
MODULE_LICENSE("GPL");

include/scsi/scsi_proto.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef _SCSI_PROTO_H_
1111
#define _SCSI_PROTO_H_
1212

13+
#include <linux/build_bug.h>
1314
#include <linux/types.h>
1415

1516
/*
@@ -126,6 +127,7 @@
126127
#define SAI_READ_CAPACITY_16 0x10
127128
#define SAI_GET_LBA_STATUS 0x12
128129
#define SAI_REPORT_REFERRALS 0x13
130+
#define SAI_GET_STREAM_STATUS 0x16
129131
/* values for maintenance in */
130132
#define MI_REPORT_IDENTIFYING_INFORMATION 0x05
131133
#define MI_REPORT_TARGET_PGS 0x0a
@@ -275,6 +277,82 @@ struct scsi_lun {
275277
__u8 scsi_lun[8];
276278
};
277279

280+
/* SBC-5 IO advice hints group descriptor */
281+
struct scsi_io_group_descriptor {
282+
#if defined(__BIG_ENDIAN)
283+
u8 io_advice_hints_mode: 2;
284+
u8 reserved1: 3;
285+
u8 st_enble: 1;
286+
u8 cs_enble: 1;
287+
u8 ic_enable: 1;
288+
#elif defined(__LITTLE_ENDIAN)
289+
u8 ic_enable: 1;
290+
u8 cs_enble: 1;
291+
u8 st_enble: 1;
292+
u8 reserved1: 3;
293+
u8 io_advice_hints_mode: 2;
294+
#else
295+
#error
296+
#endif
297+
u8 reserved2[3];
298+
/* Logical block markup descriptor */
299+
#if defined(__BIG_ENDIAN)
300+
u8 acdlu: 1;
301+
u8 reserved3: 1;
302+
u8 rlbsr: 2;
303+
u8 lbm_descriptor_type: 4;
304+
#elif defined(__LITTLE_ENDIAN)
305+
u8 lbm_descriptor_type: 4;
306+
u8 rlbsr: 2;
307+
u8 reserved3: 1;
308+
u8 acdlu: 1;
309+
#else
310+
#error
311+
#endif
312+
u8 params[2];
313+
u8 reserved4;
314+
u8 reserved5[8];
315+
};
316+
317+
static_assert(sizeof(struct scsi_io_group_descriptor) == 16);
318+
319+
/* SCSI stream status descriptor */
320+
struct scsi_stream_status {
321+
#if defined(__BIG_ENDIAN)
322+
u8 perm: 1;
323+
u8 reserved1: 7;
324+
#elif defined(__LITTLE_ENDIAN)
325+
u8 reserved1: 7;
326+
u8 perm: 1;
327+
#else
328+
#error
329+
#endif
330+
u8 reserved2;
331+
__be16 stream_identifier;
332+
#if defined(__BIG_ENDIAN)
333+
u8 reserved3: 2;
334+
u8 rel_lifetime: 6;
335+
#elif defined(__LITTLE_ENDIAN)
336+
u8 rel_lifetime: 6;
337+
u8 reserved3: 2;
338+
#else
339+
#error
340+
#endif
341+
u8 reserved4[3];
342+
};
343+
344+
static_assert(sizeof(struct scsi_stream_status) == 8);
345+
346+
/* GET STREAM STATUS parameter data */
347+
struct scsi_stream_status_header {
348+
__be32 len; /* length in bytes of stream_status[] array. */
349+
u16 reserved;
350+
__be16 number_of_open_streams;
351+
DECLARE_FLEX_ARRAY(struct scsi_stream_status, stream_status);
352+
};
353+
354+
static_assert(sizeof(struct scsi_stream_status_header) == 8);
355+
278356
/* SPC asymmetric access states */
279357
#define SCSI_ACCESS_STATE_OPTIMAL 0x00
280358
#define SCSI_ACCESS_STATE_ACTIVE 0x01

0 commit comments

Comments
 (0)