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.

at 4d8e74ad4585672489da6145b3328d415f50db82 142 lines 5.0 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2#ifndef _UAPIBSG_H 3#define _UAPIBSG_H 4 5#ifdef __KERNEL__ 6#include <linux/build_bug.h> 7#endif /* __KERNEL__ */ 8#include <linux/types.h> 9 10#define BSG_PROTOCOL_SCSI 0 11 12#define BSG_SUB_PROTOCOL_SCSI_CMD 0 13#define BSG_SUB_PROTOCOL_SCSI_TMF 1 14#define BSG_SUB_PROTOCOL_SCSI_TRANSPORT 2 15 16/* 17 * For flag constants below: 18 * sg.h sg_io_hdr also has bits defined for it's flags member. These 19 * two flag values (0x10 and 0x20) have the same meaning in sg.h . For 20 * bsg the BSG_FLAG_Q_AT_HEAD flag is ignored since it is the deafult. 21 */ 22#define BSG_FLAG_Q_AT_TAIL 0x10 /* default is Q_AT_HEAD */ 23#define BSG_FLAG_Q_AT_HEAD 0x20 24 25struct sg_io_v4 { 26 __s32 guard; /* [i] 'Q' to differentiate from v3 */ 27 __u32 protocol; /* [i] 0 -> SCSI , .... */ 28 __u32 subprotocol; /* [i] 0 -> SCSI command, 1 -> SCSI task 29 management function, .... */ 30 31 __u32 request_len; /* [i] in bytes */ 32 __u64 request; /* [i], [*i] {SCSI: cdb} */ 33 __u64 request_tag; /* [i] {SCSI: task tag (only if flagged)} */ 34 __u32 request_attr; /* [i] {SCSI: task attribute} */ 35 __u32 request_priority; /* [i] {SCSI: task priority} */ 36 __u32 request_extra; /* [i] {spare, for padding} */ 37 __u32 max_response_len; /* [i] in bytes */ 38 __u64 response; /* [i], [*o] {SCSI: (auto)sense data} */ 39 40 /* "dout_": data out (to device); "din_": data in (from device) */ 41 __u32 dout_iovec_count; /* [i] 0 -> "flat" dout transfer else 42 dout_xfer points to array of iovec */ 43 __u32 dout_xfer_len; /* [i] bytes to be transferred to device */ 44 __u32 din_iovec_count; /* [i] 0 -> "flat" din transfer */ 45 __u32 din_xfer_len; /* [i] bytes to be transferred from device */ 46 __u64 dout_xferp; /* [i], [*i] */ 47 __u64 din_xferp; /* [i], [*o] */ 48 49 __u32 timeout; /* [i] units: millisecond */ 50 __u32 flags; /* [i] bit mask */ 51 __u64 usr_ptr; /* [i->o] unused internally */ 52 __u32 spare_in; /* [i] */ 53 54 __u32 driver_status; /* [o] 0 -> ok */ 55 __u32 transport_status; /* [o] 0 -> ok */ 56 __u32 device_status; /* [o] {SCSI: command completion status} */ 57 __u32 retry_delay; /* [o] {SCSI: status auxiliary information} */ 58 __u32 info; /* [o] additional information */ 59 __u32 duration; /* [o] time to complete, in milliseconds */ 60 __u32 response_len; /* [o] bytes of response actually written */ 61 __s32 din_resid; /* [o] din_xfer_len - actual_din_xfer_len */ 62 __s32 dout_resid; /* [o] dout_xfer_len - actual_dout_xfer_len */ 63 __u64 generated_tag; /* [o] {SCSI: transport generated task tag} */ 64 __u32 spare_out; /* [o] */ 65 66 __u32 padding; 67}; 68 69struct bsg_uring_cmd { 70 __u64 request; /* [i], [*i] command descriptor address */ 71 __u32 request_len; /* [i] command descriptor length in bytes */ 72 __u32 protocol; /* [i] protocol type (BSG_PROTOCOL_*) */ 73 __u32 subprotocol; /* [i] subprotocol type (BSG_SUB_PROTOCOL_*) */ 74 __u32 max_response_len; /* [i] response buffer size in bytes */ 75 76 __u64 response; /* [i], [*o] response data address */ 77 __u64 dout_xferp; /* [i], [*i] */ 78 __u32 dout_xfer_len; /* [i] bytes to be transferred to device */ 79 __u32 dout_iovec_count; /* [i] 0 -> "flat" dout transfer else 80 * dout_xferp points to array of iovec 81 */ 82 __u64 din_xferp; /* [i], [*o] */ 83 __u32 din_xfer_len; /* [i] bytes to be transferred from device */ 84 __u32 din_iovec_count; /* [i] 0 -> "flat" din transfer */ 85 86 __u32 timeout_ms; /* [i] timeout in milliseconds */ 87 __u8 reserved[12]; /* reserved for future extension */ 88}; 89 90#ifdef __KERNEL__ 91/* Must match IORING_OP_URING_CMD payload size (e.g. SQE128). */ 92static_assert(sizeof(struct bsg_uring_cmd) == 80); 93#endif /* __KERNEL__ */ 94 95 96/* 97 * SCSI BSG io_uring completion (res2, 64-bit) 98 * 99 * When using BSG_PROTOCOL_SCSI + BSG_SUB_PROTOCOL_SCSI_CMD with 100 * IORING_OP_URING_CMD, the completion queue entry (CQE) contains: 101 * - result: errno (0 on success) 102 * - res2: packed SCSI status 103 * 104 * res2 bit layout: 105 * [0..7] device_status (SCSI status byte, e.g. CHECK_CONDITION) 106 * [8..15] driver_status (e.g. DRIVER_SENSE when sense data is valid) 107 * [16..23] host_status (e.g. DID_OK, DID_TIME_OUT) 108 * [24..31] sense_len_wr (bytes of sense data written to response buffer) 109 * [32..63] resid_len (residual transfer length) 110 */ 111static inline __u8 bsg_scsi_res2_device_status(__u64 res2) 112{ 113 return res2 & 0xff; 114} 115static inline __u8 bsg_scsi_res2_driver_status(__u64 res2) 116{ 117 return res2 >> 8; 118} 119static inline __u8 bsg_scsi_res2_host_status(__u64 res2) 120{ 121 return res2 >> 16; 122} 123static inline __u8 bsg_scsi_res2_sense_len(__u64 res2) 124{ 125 return res2 >> 24; 126} 127static inline __u32 bsg_scsi_res2_resid_len(__u64 res2) 128{ 129 return res2 >> 32; 130} 131static inline __u64 bsg_scsi_res2_build(__u8 device_status, __u8 driver_status, 132 __u8 host_status, __u8 sense_len_wr, 133 __u32 resid_len) 134{ 135 return ((__u64)(__u32)(resid_len) << 32) | 136 ((__u64)sense_len_wr << 24) | 137 ((__u64)host_status << 16) | 138 ((__u64)driver_status << 8) | 139 (__u64)device_status; 140} 141 142#endif /* _UAPIBSG_H */