Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bsg: add bsg_uring_cmd uapi structure

Add the bsg_uring_cmd structure to the BSG UAPI header to support
io_uring-based SCSI passthrough operations via IORING_OP_URING_CMD.

Signed-off-by: Yang Xiuwei <yangxiuwei@kylinos.cn>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Link: https://patch.msgid.link/20260317072226.2598233-2-yangxiuwei@kylinos.cn
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Yang Xiuwei and committed by
Jens Axboe
7da9261b 64389364

+75
+75
include/uapi/linux/bsg.h
··· 2 2 #ifndef _UAPIBSG_H 3 3 #define _UAPIBSG_H 4 4 5 + #ifdef __KERNEL__ 6 + #include <linux/build_bug.h> 7 + #endif /* __KERNEL__ */ 5 8 #include <linux/types.h> 6 9 7 10 #define BSG_PROTOCOL_SCSI 0 ··· 66 63 __u32 padding; 67 64 }; 68 65 66 + struct bsg_uring_cmd { 67 + __u64 request; /* [i], [*i] command descriptor address */ 68 + __u32 request_len; /* [i] command descriptor length in bytes */ 69 + __u32 protocol; /* [i] protocol type (BSG_PROTOCOL_*) */ 70 + __u32 subprotocol; /* [i] subprotocol type (BSG_SUB_PROTOCOL_*) */ 71 + __u32 max_response_len; /* [i] response buffer size in bytes */ 72 + 73 + __u64 response; /* [i], [*o] response data address */ 74 + __u64 dout_xferp; /* [i], [*i] */ 75 + __u32 dout_xfer_len; /* [i] bytes to be transferred to device */ 76 + __u32 dout_iovec_count; /* [i] 0 -> "flat" dout transfer else 77 + * dout_xferp points to array of iovec 78 + */ 79 + __u64 din_xferp; /* [i], [*o] */ 80 + __u32 din_xfer_len; /* [i] bytes to be transferred from device */ 81 + __u32 din_iovec_count; /* [i] 0 -> "flat" din transfer */ 82 + 83 + __u32 timeout_ms; /* [i] timeout in milliseconds */ 84 + __u8 reserved[12]; /* reserved for future extension */ 85 + }; 86 + 87 + #ifdef __KERNEL__ 88 + /* Must match IORING_OP_URING_CMD payload size (e.g. SQE128). */ 89 + static_assert(sizeof(struct bsg_uring_cmd) == 80); 90 + #endif /* __KERNEL__ */ 91 + 92 + 93 + /* 94 + * SCSI BSG io_uring completion (res2, 64-bit) 95 + * 96 + * When using BSG_PROTOCOL_SCSI + BSG_SUB_PROTOCOL_SCSI_CMD with 97 + * IORING_OP_URING_CMD, the completion queue entry (CQE) contains: 98 + * - result: errno (0 on success) 99 + * - res2: packed SCSI status 100 + * 101 + * res2 bit layout: 102 + * [0..7] device_status (SCSI status byte, e.g. CHECK_CONDITION) 103 + * [8..15] driver_status (e.g. DRIVER_SENSE when sense data is valid) 104 + * [16..23] host_status (e.g. DID_OK, DID_TIME_OUT) 105 + * [24..31] sense_len_wr (bytes of sense data written to response buffer) 106 + * [32..63] resid_len (residual transfer length) 107 + */ 108 + static inline __u8 bsg_scsi_res2_device_status(__u64 res2) 109 + { 110 + return res2 & 0xff; 111 + } 112 + static inline __u8 bsg_scsi_res2_driver_status(__u64 res2) 113 + { 114 + return res2 >> 8; 115 + } 116 + static inline __u8 bsg_scsi_res2_host_status(__u64 res2) 117 + { 118 + return res2 >> 16; 119 + } 120 + static inline __u8 bsg_scsi_res2_sense_len(__u64 res2) 121 + { 122 + return res2 >> 24; 123 + } 124 + static inline __u32 bsg_scsi_res2_resid_len(__u64 res2) 125 + { 126 + return res2 >> 32; 127 + } 128 + static inline __u64 bsg_scsi_res2_build(__u8 device_status, __u8 driver_status, 129 + __u8 host_status, __u8 sense_len_wr, 130 + __u32 resid_len) 131 + { 132 + return ((__u64)(__u32)(resid_len) << 32) | 133 + ((__u64)sense_len_wr << 24) | 134 + ((__u64)host_status << 16) | 135 + ((__u64)driver_status << 8) | 136 + (__u64)device_status; 137 + } 69 138 70 139 #endif /* _UAPIBSG_H */