ublksrv_tgt: add helpers for supporting ublk unique tag
The use is same with linux kernel's blk-mq's unique tag.
Signed-off-by: Ming Lei <[email protected]>
diff --git a/include/ublksrv_tgt.h b/include/ublksrv_tgt.h
index 6384cb9..4605b2d 100644
--- a/include/ublksrv_tgt.h
+++ b/include/ublksrv_tgt.h
@@ -132,4 +132,25 @@
extern int ublksrv_register_tgt_type(struct ublksrv_tgt_type *type);
extern void ublksrv_unregister_tgt_type(struct ublksrv_tgt_type *type);
+enum {
+ UBLK_UNIQUE_TAG_BITS = 16,
+ UBLK_UNIQUE_TAG_MASK = (1 << UBLK_UNIQUE_TAG_BITS) - 1,
+};
+
+static inline unsigned int ublk_unique_tag(unsigned short hwq,
+ unsigned short tag)
+{
+ return (hwq << UBLK_UNIQUE_TAG_BITS) | (tag & UBLK_UNIQUE_TAG_MASK);
+}
+
+static inline unsigned short ublk_unique_tag_to_hwq(unsigned int unique_tag)
+{
+ return unique_tag >> UBLK_UNIQUE_TAG_BITS;
+}
+
+static inline unsigned short ublk_unique_tag_to_tag(unsigned int unique_tag)
+{
+ return unique_tag & UBLK_UNIQUE_TAG_MASK;
+}
+
#endif