From: Brian Bunker <brian@purestorage.com>
To: hare@suse.de, linux-scsi@vger.kernel.org
Cc: Brian Bunker <brian@purestorage.com>,
Krishna Kant <krishna.kant@purestorage.com>
Subject: [PATCH 1/6] scsi: Add INQUIRY data field definitions and accessor helpers
Date: Fri, 24 Apr 2026 14:53:19 -0700 [thread overview]
Message-ID: <20260424215324.99045-2-brian@purestorage.com> (raw)
In-Reply-To: <20260424215324.99045-1-brian@purestorage.com>
Add well-documented inline functions and macros to parse INQUIRY data
fields according to SPC-6 section 6.7.2. These helpers provide a
consistent interface for extracting:
- Peripheral qualifier and device type from byte 0
- Removable media bit from byte 1
- Response data format from byte 3
- Capability flags (WBUS16, SYNC, CMDQUE, SFTRE) from byte 7
- Vendor, product, and revision strings
This is preparatory work for adding INQUIRY data update support during
device rescan operations.
Signed-off-by: Brian Bunker <brian@purestorage.com>
Signed-off-by: Krishna Kant <krishna.kant@purestorage.com>
---
include/scsi/scsi.h | 171 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 171 insertions(+)
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index 08ac3200b4a4b..8f38d9a884f91 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -172,6 +172,177 @@ enum scsi_qc_status {
#define SCSI_INQ_PQ_NOT_CON 0x01
#define SCSI_INQ_PQ_NOT_CAP 0x03
+/*
+ * INQUIRY data field offsets and lengths
+ */
+#define SCSI_INQ_STD_LEN 36 /* Min standard INQ len */
+#define SCSI_INQ_VENDOR_OFFSET 8
+#define SCSI_INQ_VENDOR_LEN 8
+#define SCSI_INQ_PRODUCT_OFFSET 16
+#define SCSI_INQ_PRODUCT_LEN 16
+#define SCSI_INQ_REVISION_OFFSET 32
+#define SCSI_INQ_REVISION_LEN 4
+
+/*
+ * INQUIRY data byte 0 bit masks
+ */
+#define SCSI_INQ_PERIPH_QUAL_MASK 0xe0 /* bits 5-7 */
+#define SCSI_INQ_PERIPH_QUAL_SHIFT 5
+#define SCSI_INQ_DEVICE_TYPE_MASK 0x1f /* bits 0-4 */
+
+/*
+ * INQUIRY data byte 1 bit masks
+ */
+#define SCSI_INQ_RMB_MASK 0x80 /* bit 7 */
+
+/*
+ * INQUIRY data byte 3 bit masks
+ */
+#define SCSI_INQ_RESP_DATA_FMT_MASK 0x0f /* bits 0-3 */
+
+/*
+ * INQUIRY data byte 7 bit masks
+ */
+#define SCSI_INQ_WBUS16 0x20 /* Wide Bus 16 (bit 5) */
+#define SCSI_INQ_SYNC 0x10 /* Synchronous (bit 4) */
+#define SCSI_INQ_CMDQUE 0x02 /* Command Queuing (bit 1) */
+#define SCSI_INQ_SFTRE 0x01 /* Soft Reset (bit 0) */
+
+/**
+ * scsi_inq_periph_qual - Extract peripheral qualifier from byte 0
+ * @inq_byte0: INQUIRY data byte 0
+ *
+ * Returns: Peripheral Qualifier (0-7)
+ */
+static inline unsigned char scsi_inq_periph_qual(unsigned char inq_byte0)
+{
+ return (inq_byte0 & SCSI_INQ_PERIPH_QUAL_MASK) >>
+ SCSI_INQ_PERIPH_QUAL_SHIFT;
+}
+
+/**
+ * scsi_inq_device_type - Extract device type from byte 0
+ * @inq_byte0: INQUIRY data byte 0
+ * @lun: Logical Unit Number
+ *
+ * Extracts the peripheral device type. For well-known logical units
+ * (W-LUNs), corrects the type to TYPE_WLUN if device reports wrong type.
+ *
+ * Returns: Peripheral Device Type (0-31)
+ */
+static inline unsigned char scsi_inq_device_type(unsigned char inq_byte0,
+ u64 lun)
+{
+ unsigned char type = inq_byte0 & SCSI_INQ_DEVICE_TYPE_MASK;
+
+ /*
+ * Some devices respond with wrong type for well-known logical
+ * units. Force well-known type to enumerate them correctly.
+ */
+ if (scsi_is_wlun(lun) && type != TYPE_WLUN)
+ type = TYPE_WLUN;
+
+ return type;
+}
+
+/**
+ * scsi_inq_removable - Extract removable media bit from byte 1
+ * @inq_byte1: INQUIRY data byte 1
+ *
+ * Returns: true if removable, false if not
+ */
+static inline bool scsi_inq_removable(unsigned char inq_byte1)
+{
+ return inq_byte1 & SCSI_INQ_RMB_MASK;
+}
+
+/**
+ * scsi_inq_resp_data_fmt - Extract response data format from byte 3
+ * @inq_byte3: INQUIRY data byte 3
+ *
+ * Returns: Response Data Format (0-15)
+ */
+static inline unsigned char scsi_inq_resp_data_fmt(unsigned char inq_byte3)
+{
+ return inq_byte3 & SCSI_INQ_RESP_DATA_FMT_MASK;
+}
+
+/**
+ * scsi_inq_wbus16 - Check wide bus support from byte 7
+ * @inq_byte7: INQUIRY data byte 7
+ *
+ * Returns: true if 16-bit wide bus supported, false if not
+ */
+static inline bool scsi_inq_wbus16(unsigned char inq_byte7)
+{
+ return inq_byte7 & SCSI_INQ_WBUS16;
+}
+
+/**
+ * scsi_inq_sync - Check synchronous transfer support from byte 7
+ * @inq_byte7: INQUIRY data byte 7
+ *
+ * Returns: true if synchronous transfers supported, false if not
+ */
+static inline bool scsi_inq_sync(unsigned char inq_byte7)
+{
+ return inq_byte7 & SCSI_INQ_SYNC;
+}
+
+/**
+ * scsi_inq_cmdque - Check command queuing support from byte 7
+ * @inq_byte7: INQUIRY data byte 7
+ *
+ * Returns: true if command queuing supported, false if not
+ */
+static inline bool scsi_inq_cmdque(unsigned char inq_byte7)
+{
+ return inq_byte7 & SCSI_INQ_CMDQUE;
+}
+
+/**
+ * scsi_inq_sftre - Check soft reset support from byte 7
+ * @inq_byte7: INQUIRY data byte 7
+ *
+ * Returns: true if soft reset supported, false if not
+ */
+static inline bool scsi_inq_sftre(unsigned char inq_byte7)
+{
+ return inq_byte7 & SCSI_INQ_SFTRE;
+}
+
+/**
+ * scsi_inq_vendor - Get pointer to vendor string
+ * @inq_data: Pointer to INQUIRY data buffer
+ *
+ * Returns: Pointer to 8-byte vendor string (not null-terminated)
+ */
+static inline const char *scsi_inq_vendor(const unsigned char *inq_data)
+{
+ return (const char *)(inq_data + SCSI_INQ_VENDOR_OFFSET);
+}
+
+/**
+ * scsi_inq_product - Get pointer to product string
+ * @inq_data: Pointer to INQUIRY data buffer
+ *
+ * Returns: Pointer to 16-byte product string (not null-terminated)
+ */
+static inline const char *scsi_inq_product(const unsigned char *inq_data)
+{
+ return (const char *)(inq_data + SCSI_INQ_PRODUCT_OFFSET);
+}
+
+/**
+ * scsi_inq_revision - Get pointer to revision string
+ * @inq_data: Pointer to INQUIRY data buffer
+ *
+ * Returns: Pointer to 4-byte revision string (not null-terminated)
+ */
+static inline const char *scsi_inq_revision(const unsigned char *inq_data)
+{
+ return (const char *)(inq_data + SCSI_INQ_REVISION_OFFSET);
+}
/*
* Here are some scsi specific ioctl commands which are sometimes useful.
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2026-04-24 21:53 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-24 21:53 [PATCH 0/6] scsi: Support ALUA unavailable state and INQUIRY changes Brian Bunker
2026-04-24 21:53 ` Brian Bunker [this message]
2026-04-27 8:19 ` [PATCH 1/6] scsi: Add INQUIRY data field definitions and accessor helpers Hannes Reinecke
2026-04-30 15:50 ` Bart Van Assche
2026-04-24 21:53 ` [PATCH 2/6] scsi: Protect INQUIRY sysfs attributes with mutex Brian Bunker
2026-04-27 8:22 ` Hannes Reinecke
2026-04-29 1:27 ` [PATCH v2 " Brian Bunker
2026-04-29 21:06 ` Damien Le Moal
2026-04-29 21:15 ` Bart Van Assche
2026-04-29 22:49 ` [PATCH v3 " Brian Bunker
2026-04-30 6:03 ` Hannes Reinecke
2026-04-30 15:48 ` Bart Van Assche
2026-05-01 22:11 ` Brian Bunker
2026-05-02 16:37 ` Bart Van Assche
2026-05-03 15:44 ` Bart Van Assche
2026-05-04 18:36 ` Brian Bunker
2026-05-05 8:24 ` Bart Van Assche
2026-05-05 17:13 ` Brian Bunker
2026-04-24 21:53 ` [PATCH 3/6] scsi: Add scsi_update_inquiry_data() for updating INQUIRY data Brian Bunker
2026-04-24 21:53 ` [PATCH 4/6] scsi: Refactor scsi_add_lun() to use scsi_update_inquiry_data() Brian Bunker
2026-04-24 21:53 ` [PATCH 5/6] scsi: Add device reprobe support to scsi_rescan_device() Brian Bunker
2026-04-24 21:53 ` [PATCH 6/6] scsi: Handle reprobe for existing devices during SCSI scan Brian Bunker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260424215324.99045-2-brian@purestorage.com \
--to=brian@purestorage.com \
--cc=hare@suse.de \
--cc=krishna.kant@purestorage.com \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox