1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 #ifndef _UAPI_SCSI_SG_H 3 #define _UAPI_SCSI_SG_H 4 5 /* 6 * History: 7 * Started: Aug 9 by Lawrence Foard ([email protected]), to allow user 8 * process control of SCSI devices. 9 * Development Sponsored by Killy Corp. NY NY 10 * 11 * Original driver (sg.h): 12 * Copyright (C) 1992 Lawrence Foard 13 * 14 * Later extensions (versions 2, 3 and 4) to driver: 15 * Copyright (C) 1998 - 2021 Douglas Gilbert 16 * 17 * Version 4.0.47 (20210605) 18 * This version is for Linux 4 and 5 series kernels. 19 * 20 * Documentation 21 * ============= 22 * A web site for the SG device driver can be found at: 23 * https://sg.danny.cz/sg [alternatively check the MAINTAINERS file] 24 * The documentation for the sg version 3 driver can be found at: 25 * https://sg.danny.cz/sg/p/sg_v3_ho.html 26 * Also see: <kernel_source>/Documentation/scsi/scsi-generic.txt 27 * 28 * For utility and test programs see: https://sg.danny.cz/sg/sg3_utils.html 29 */ 30 31 #include <stddef.h> 32 #include <linux/types.h> 33 #include <linux/major.h> 34 35 /* 36 * bsg.h contains the sg v4 user space interface structure (sg_io_v4). 37 * That structure is also used as the controlling object when multiple 38 * requests are issued with one ioctl() call. 39 */ 40 #include <linux/bsg.h> 41 42 /* 43 * Same structure as used by readv() call. It defines one scatter-gather 44 * element. "Scatter-gather" is abbreviated to "sgat" in this driver to 45 * avoid confusion with this driver's name. 46 */ 47 typedef struct sg_iovec { 48 void __user *iov_base; /* Starting address (of a byte) */ 49 size_t iov_len; /* Length in bytes */ 50 } sg_iovec_t; 51 52 53 typedef struct sg_io_hdr { 54 int interface_id; /* [i] 'S' for SCSI generic (required) */ 55 int dxfer_direction; /* [i] data transfer direction */ 56 unsigned char cmd_len; /* [i] SCSI command length */ 57 unsigned char mx_sb_len;/* [i] max length to write to sbp */ 58 unsigned short iovec_count; /* [i] 0 implies no sgat list */ 59 unsigned int dxfer_len; /* [i] byte count of data transfer */ 60 /* dxferp points to data transfer memory or scatter gather list */ 61 void __user *dxferp; /* [i], [*io] */ 62 unsigned char __user *cmdp;/* [i], [*i] points to command to perform */ 63 void __user *sbp; /* [i], [*o] points to sense_buffer memory */ 64 unsigned int timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */ 65 unsigned int flags; /* [i] 0 -> default, see SG_FLAG... */ 66 int pack_id; /* [i->o] unused internally (normally) */ 67 void __user *usr_ptr; /* [i->o] unused internally */ 68 unsigned char status; /* [o] scsi status */ 69 unsigned char masked_status;/* [o] shifted, masked scsi status */ 70 unsigned char msg_status;/* [o] messaging level data (optional) */ 71 unsigned char sb_len_wr; /* [o] byte count actually written to sbp */ 72 unsigned short host_status; /* [o] errors from host adapter */ 73 unsigned short driver_status;/* [o] errors from software driver */ 74 int resid; /* [o] dxfer_len - actual_transferred */ 75 /* unit may be nanoseconds after SG_SET_GET_EXTENDED ioctl use */ 76 unsigned int duration; /* [o] time taken by cmd (unit: millisec) */ 77 unsigned int info; /* [o] auxiliary information */ 78 } sg_io_hdr_t; 79 80 #define SG_INTERFACE_ID_ORIG 'S' 81 82 /* Use negative values to flag difference from original sg_header structure */ 83 #define SG_DXFER_NONE (-1) /* e.g. a SCSI Test Unit Ready command */ 84 #define SG_DXFER_TO_DEV (-2) /* data-out buffer e.g. SCSI WRITE command */ 85 #define SG_DXFER_FROM_DEV (-3) /* data-in buffer e.g. SCSI READ command */ 86 /* 87 * SG_DXFER_TO_FROM_DEV is treated like SG_DXFER_FROM_DEV with the additional 88 * property than during indirect IO the user buffer is copied into the kernel 89 * buffers _before_ the transfer from the device takes place. Useful if short 90 * DMA transfers (less than requested) are not reported (e.g. resid always 0). 91 */ 92 #define SG_DXFER_TO_FROM_DEV (-4) 93 #define SG_DXFER_UNKNOWN (-5) /* Unknown data direction, do not use */ 94 95 /* following flag values can be OR-ed together in v3::flags or v4::flags */ 96 #define SG_FLAG_DIRECT_IO 1 /* default is indirect IO */ 97 /* SG_FLAG_UNUSED_LUN_INHIBIT is ignored in sg v4 driver */ 98 #define SG_FLAG_UNUSED_LUN_INHIBIT 2 /* ignored, was LUN overwrite in cdb */ 99 #define SG_FLAG_MMAP_IO 4 /* request memory mapped IO */ 100 /* no transfers between kernel<-->user space; keep device<-->kernel xfers */ 101 #define SG_FLAG_NO_DXFER 0x10000 /* See comment on previous line! */ 102 /* defaults: for sg driver (v3_v4): Q_AT_HEAD; for block layer: Q_AT_TAIL */ 103 #define SG_FLAG_Q_AT_TAIL 0x10 104 #define SG_FLAG_Q_AT_HEAD 0x20 105 106 /* 107 * Flags used by ioctl(SG_IOSUBMIT) [abbrev: SG_IOS] and ioctl(SG_IORECEIVE) 108 * [abbrev: SG_IOR] OR-ed into sg_io_v4::flags. The sync v4 interface uses 109 * ioctl(SG_IO) and can take these new flags, as can the v3 interface. 110 * These flags apply for SG_IOS unless otherwise noted. May be OR-ed together. 111 */ 112 #define SGV4_FLAG_DIRECT_IO SG_FLAG_DIRECT_IO 113 #define SGV4_FLAG_MMAP_IO SG_FLAG_MMAP_IO 114 #define SGV4_FLAG_YIELD_TAG 0x8 /* sg_io_v4::generated_tag set after SG_IOS */ 115 #define SGV4_FLAG_Q_AT_TAIL SG_FLAG_Q_AT_TAIL 116 #define SGV4_FLAG_Q_AT_HEAD SG_FLAG_Q_AT_HEAD 117 #define SGV4_FLAG_DOUT_OFFSET 0x40 /* dout byte offset in v4::spare_in */ 118 #define SGV4_FLAG_EVENTFD 0x80 /* signal completion on ... */ 119 #define SGV4_FLAG_COMPLETE_B4 0x100 /* mrq: complete this rq before next */ 120 #define SGV4_FLAG_SIGNAL 0x200 /* v3: ignored; v4 signal on completion */ 121 #define SGV4_FLAG_IMMED 0x400 /* issue request and return immediately ... */ 122 #define SGV4_FLAG_HIPRI 0x800 /* use blk_poll (deprecated name, use POLLED) */ 123 #define SGV4_FLAG_POLLED 0x800 /* request will use blk_poll to complete */ 124 #define SGV4_FLAG_STOP_IF 0x1000 /* Stops sync mrq if error or warning */ 125 #define SGV4_FLAG_DEV_SCOPE 0x2000 /* permit SG_IOABORT to have wider scope */ 126 #define SGV4_FLAG_SHARE 0x4000 /* share IO buffer; needs SG_SEIM_SHARE_FD */ 127 #define SGV4_FLAG_DO_ON_OTHER 0x8000 /* available on either of shared pair */ 128 #define SGV4_FLAG_NO_DXFER SG_FLAG_NO_DXFER /* but keep dev<-->kernel xfr */ 129 #define SGV4_FLAG_KEEP_SHARE 0x20000 /* ... buffer for another dout command */ 130 #define SGV4_FLAG_MULTIPLE_REQS 0x40000 /* 1 or more sg_io_v4-s in data-in */ 131 #define SGV4_FLAG_ORDERED_WR 0x80000 /* svb: issue in-order writes */ 132 #define SGV4_FLAG_REC_ORDER 0x100000 /* receive order in v4:request_priority */ 133 #define SGV4_FLAG_META_OUT_IF 0x200000 /* ... there is something to report */ 134 135 /* Output (potentially OR-ed together) in v3::info or v4::info field */ 136 #define SG_INFO_OK_MASK 0x1 137 #define SG_INFO_OK 0x0 /* no sense, host nor driver "noise" */ 138 #define SG_INFO_CHECK 0x1 /* something abnormal happened */ 139 140 #define SG_INFO_DIRECT_IO_MASK 0x6 141 #define SG_INFO_INDIRECT_IO 0x0 /* data xfer via kernel buffers (or no xfer) */ 142 #define SG_INFO_DIRECT_IO 0x2 /* direct IO requested and performed */ 143 #define SG_INFO_MIXED_IO 0x4 /* not used, always 0 */ 144 #define SG_INFO_DEVICE_DETACHING 0x8 /* completed successfully but ... */ 145 #define SG_INFO_ABORTED 0x10 /* this command has been aborted */ 146 #define SG_INFO_MRQ_FINI 0x20 /* marks multi-reqs that have finished */ 147 148 /* 149 * Pointer to object of this structure filled by ioctl(SG_GET_SCSI_ID). Last 150 * field changed in v4 driver, was 'int unused[2]' so remains the same size. 151 */ 152 typedef struct sg_scsi_id { 153 int host_no; /* as in "scsi<n>" where 'n' is one of 0, 1, 2 etc */ 154 int channel; 155 int scsi_id; /* scsi id of target device */ 156 int lun; /* lower 32 bits of internal 64 bit integer */ 157 int scsi_type; /* TYPE_... defined in scsi/scsi.h */ 158 short h_cmd_per_lun;/* host (adapter) maximum commands per lun */ 159 short d_queue_depth;/* device (or adapter) maximum queue length */ 160 union { 161 int unused[2]; /* as per version 3 driver */ 162 __u8 scsi_lun[8]; /* full 8 byte SCSI LUN [in v4 driver] */ 163 }; 164 } sg_scsi_id_t; 165 166 /* For backward compatibility v4 driver yields at most SG_MAX_QUEUE of these */ 167 typedef struct sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */ 168 char req_state; /* See 'enum sg_rq_state' definition in v4 driver */ 169 char orphan; /* 0 -> normal request, 1 -> from interrupted SG_IO */ 170 /* sg_io_owned set imples synchronous, clear implies asynchronous */ 171 char sg_io_owned;/* 0 -> complete with read(), 1 -> owned by SG_IO */ 172 char problem; /* 0 -> no problem detected, 1 -> error to report */ 173 /* If SG_CTL_FLAGM_TAG_FOR_PACK_ID set on fd then next field is tag */ 174 int pack_id; /* pack_id, in v4 driver may be tag instead */ 175 void __user *usr_ptr; /* user provided pointer in v3+v4 interface */ 176 /* 177 * millisecs elapsed since the command started (req_state==1) or 178 * command duration (req_state==2). Will be in nanoseconds after 179 * the SG_SET_GET_EXTENDED{TIME_IN_NS} ioctl. 180 */ 181 unsigned int duration; 182 int unused; 183 } sg_req_info_t; 184 185 /* 186 * The following defines are for manipulating struct sg_extended_info which 187 * is abbreviated to "SEI". A following "M" (i.e. "_SEIM_") indicates a 188 * mask. Most mask values correspond to a integer (usually a uint32_t) apart 189 * from SG_SEIM_CTL_FLAGS which is for boolean values packed into an integer. 190 * The mask values for those booleans start with "SG_CTL_FLAGM_". The scope 191 * of these settings, like most other ioctls, is usually that of the file 192 * descriptor the ioctl is executed on. The "rd:" indication means read-only, 193 * attempts to write to them are ignored. "rd>" means action when reading. 194 */ 195 #define SG_SEIM_CTL_FLAGS 0x1 /* ctl_flags_mask bits in ctl_flags */ 196 #define SG_SEIM_READ_VAL 0x2 /* write SG_SEIRV_*, read back value */ 197 #define SG_SEIM_RESERVED_SIZE 0x4 /* reserved_sz of reserve request */ 198 #define SG_SEIM_TOT_FD_THRESH 0x8 /* tot_fd_thresh of data buffers */ 199 #define SG_SEIM_MINOR_INDEX 0x10 /* sg device minor index number */ 200 #define SG_SEIM_SHARE_FD 0x20 /* write-side gives fd of read-side */ 201 #define SG_SEIM_CHG_SHARE_FD 0x40 /* read-side given new write-side fd */ 202 #define SG_SEIM_SGAT_ELEM_SZ 0x80 /* sgat element size (>= PAGE_SIZE) */ 203 #define SG_SEIM_BLK_POLL 0x100 /* call blk_poll, uses 'num' field */ 204 #define SG_SEIM_EVENTFD 0x200 /* pass eventfd to driver */ 205 #define SG_SEIM_ALL_BITS 0x3ff /* should be OR of previous items */ 206 207 /* flag and mask values for boolean fields follow */ 208 #define SG_CTL_FLAGM_TIME_IN_NS 0x1 /* time: nanosecs (def: millisecs) */ 209 #define SG_CTL_FLAGM_TAG_FOR_PACK_ID 0x2 /* prefer tag over pack_id (def) */ 210 #define SG_CTL_FLAGM_OTHER_OPENS 0x4 /* rd: other sg fd_s on this dev */ 211 #define SG_CTL_FLAGM_ORPHANS 0x8 /* rd: orphaned requests on this fd */ 212 #define SG_CTL_FLAGM_Q_TAIL 0x10 /* used for future cmds on this fd */ 213 #define SG_CTL_FLAGM_IS_SHARE 0x20 /* rd: fd is read-side or write-side share */ 214 #define SG_CTL_FLAGM_IS_READ_SIDE 0x40 /* rd: this fd is read-side share */ 215 #define SG_CTL_FLAGM_UNSHARE 0x80 /* undo share after inflight cmd */ 216 /* rd> 1: read-side finished, 0: not; wr> 1: finish share post read-side */ 217 #define SG_CTL_FLAGM_READ_SIDE_FINI 0x100 /* wr> 0: setup for repeat write-side req */ 218 #define SG_CTL_FLAGM_READ_SIDE_ERR 0x200 /* rd: sharing, read-side got error */ 219 #define SG_CTL_FLAGM_NO_DURATION 0x400 /* don't calc command duration */ 220 #define SG_CTL_FLAGM_MORE_ASYNC 0x800 /* yield EAGAIN in more cases */ 221 #define SG_CTL_FLAGM_EXCL_WAITQ 0x1000 /* only 1 wake up per response */ 222 #define SG_CTL_FLAGM_SNAP_DEV 0x2000 /* output to debugfs::snapped */ 223 #define SG_CTL_FLAGM_RM_EVENTFD 0x4000 /* only if new eventfd wanted */ 224 #define SG_CTL_FLAGM_ALL_BITS 0x7fff /* should be OR of previous items */ 225 226 /* Write one of the following values to sg_extended_info::read_value, get... */ 227 #define SG_SEIRV_INT_MASK 0x0 /* get SG_SEIM_ALL_BITS */ 228 #define SG_SEIRV_BOOL_MASK 0x1 /* get SG_CTL_FLAGM_ALL_BITS */ 229 #define SG_SEIRV_VERS_NUM 0x2 /* get driver version number as int */ 230 #define SG_SEIRV_INACT_RQS 0x3 /* number of inactive requests */ 231 #define SG_SEIRV_DEV_INACT_RQS 0x4 /* sum(inactive rqs) on owning dev */ 232 #define SG_SEIRV_SUBMITTED 0x5 /* number of mrqs submitted+unread */ 233 #define SG_SEIRV_DEV_SUBMITTED 0x6 /* sum(submitted) on all dev's fds */ 234 #define SG_SEIRV_MAX_RSV_REQS 0x7 /* maximum reserve requests */ 235 #define SG_SEIRV_DEV_TS_LOWER 0x8 /* device timestamp's lower 32 bits */ 236 #define SG_SEIRV_DEV_TS_UPPER 0x9 /* device timestamp's upper 32 bits */ 237 238 /* 239 * A pointer to the following structure is passed as the third argument to 240 * ioctl(SG_SET_GET_EXTENDED). Each bit in the *_wr_mask fields causes the 241 * corresponding integer (e.g. reserved_sz) or bit (e.g. the 242 * SG_CTL_FLAG_TIME_IN_NS bit in ctl_flags) to be read from the user space 243 * and modify the driver. Each bit in the *_rd_mask fields causes the 244 * corresponding integer or bit to be fetched from the driver and written 245 * back to the user space. If the same bit is set in both the *_wr_mask and 246 * corresponding *_rd_mask fields, then which one comes first depends on the 247 * setting but no other operation will split the two. This structure is 248 * padded to 96 bytes to allow for new values to be added in the future. 249 */ 250 251 /* If both sei_wr_mask and sei_rd_mask are 0, this ioctl does nothing */ 252 struct sg_extended_info { 253 __u32 sei_wr_mask; /* OR-ed SG_SEIM_* user->driver values */ 254 __u32 sei_rd_mask; /* OR-ed SG_SEIM_* driver->user values */ 255 __u32 ctl_flags_wr_mask; /* OR-ed SG_CTL_FLAGM_* values */ 256 __u32 ctl_flags_rd_mask; /* OR-ed SG_CTL_FLAGM_* values */ 257 __u32 ctl_flags; /* bit values OR-ed, see SG_CTL_FLAGM_* */ 258 __u32 read_value; /* write SG_SEIRV_*, read back related */ 259 260 __u32 reserved_sz; /* data/sgl size of pre-allocated request */ 261 __u32 tot_fd_thresh; /* total data/sgat for this fd, 0: no limit */ 262 __u32 minor_index; /* rd: kernel's sg device minor number */ 263 __u32 share_fd; /* for SHARE_FD, CHG_SHARE_FD or EVENTFD */ 264 __u32 sgat_elem_sz; /* sgat element size (must be power of 2) */ 265 __s32 num; /* blk_poll: loop_count (-1 -> spin)) */ 266 __u8 pad_to_96[48]; /* pad so struct is 96 bytes long */ 267 }; 268 269 /* 270 * IOCTLs: Those ioctls that are relevant to the SG 3.x drivers follow. 271 * [Those that only apply to the SG 2.x drivers are at the end of the file.] 272 * (_GET_s yield result via 'int *' 3rd argument unless otherwise indicated) 273 */ 274 275 #define SG_EMULATED_HOST 0x2203 /* true for emulated host adapter (ATAPI) */ 276 277 /* 278 * Used to configure SCSI command transformation layer for ATAPI devices. 279 * Only supported by the ide-scsi driver. 20181014 No longer supported, this 280 * driver passes them to the mid-level which returns a EINVAL (22) errno. 281 * 282 * Original note: N.B. 3rd arg is not pointer but value: 3rd arg = 0 to 283 * disable transform, 1 to enable it 284 */ 285 #define SG_SET_TRANSFORM 0x2204 286 #define SG_GET_TRANSFORM 0x2205 287 288 #define SG_SET_RESERVED_SIZE 0x2275 /* request new reserved buffer size */ 289 #define SG_GET_RESERVED_SIZE 0x2272 /* actual size of reserved buffer */ 290 291 /* 292 * Historically the scsi/sg driver has used 0x22 as it ioctl base number. 293 * Add a define for that value and use it for several new ioctls added in 294 * version 4.0.01 sg driver and later. 295 */ 296 #define SG_IOCTL_MAGIC_NUM 0x22 297 298 #define SG_SET_GET_EXTENDED _IOWR(SG_IOCTL_MAGIC_NUM, 0x51, \ 299 struct sg_extended_info) 300 301 /* The following ioctl has a 'sg_scsi_id_t *' object as its 3rd argument. */ 302 #define SG_GET_SCSI_ID 0x2276 /* Yields fd's bus, chan, dev, lun + type */ 303 /* SCSI id information can also be obtained from SCSI_IOCTL_GET_IDLUN */ 304 305 /* Override host setting and always DMA using low memory ( <16MB on i386) */ 306 #define SG_SET_FORCE_LOW_DMA 0x2279 /* 0-> use adapter setting, 1-> force */ 307 #define SG_GET_LOW_DMA 0x227a /* 0-> use all ram for dma; 1-> low dma ram */ 308 309 /* 310 * When SG_SET_FORCE_PACK_ID set to 1, pack_id (or tag) is input to read() or 311 * ioctl(SG_IO_RECEIVE). These functions wait until matching packet (request/ 312 * command) is finished but they will return with EAGAIN quickly if the file 313 * descriptor was opened O_NONBLOCK or (in v4) if SGV4_FLAG_IMMED is given. 314 * The tag is used when SG_CTL_FLAGM_TAG_FOR_PACK_ID is set on the parent 315 * file descriptor (default: use pack_id). If pack_id or tag is -1 then read 316 * oldest waiting and this is the same action as when FORCE_PACK_ID is 317 * clear on the parent file descriptor. In the v4 interface the pack_id is 318 * placed the in sg_io_v4::request_extra field . 319 */ 320 #define SG_SET_FORCE_PACK_ID 0x227b /* pack_id or in v4 can be tag */ 321 #define SG_GET_PACK_ID 0x227c /* Yields oldest readable pack_id/tag, or -1 */ 322 323 #define SG_GET_NUM_WAITING 0x227d /* Number of commands awaiting read() */ 324 325 /* Yields max scatter gather tablesize allowed by current host adapter */ 326 #define SG_GET_SG_TABLESIZE 0x227F /* 0 implies can't do scatter gather */ 327 328 /* 329 * Integer form of version number: [x]xyyzz where [x] empty when x=0 . 330 * String form of version number: "[x]x.[y]y.zz" 331 */ 332 #define SG_GET_VERSION_NUM 0x2282 /* Example: version "2.1.34" yields 20134 */ 333 334 /* Returns -EBUSY if occupied. 3rd argument pointer to int (see next) */ 335 #define SG_SCSI_RESET 0x2284 336 /* 337 * Associated values that can be given to SG_SCSI_RESET follow. 338 * SG_SCSI_RESET_NO_ESCALATE may be OR-ed to the _DEVICE, _TARGET, _BUS 339 * or _HOST reset value so only that action is attempted. 340 */ 341 #define SG_SCSI_RESET_NOTHING 0 342 #define SG_SCSI_RESET_DEVICE 1 343 #define SG_SCSI_RESET_BUS 2 344 #define SG_SCSI_RESET_HOST 3 345 #define SG_SCSI_RESET_TARGET 4 346 #define SG_SCSI_RESET_NO_ESCALATE 0x100 347 348 /* synchronous SCSI command ioctl, (for version 3 and 4 interface) */ 349 #define SG_IO 0x2285 /* similar effect as write() followed by read() */ 350 351 #define SG_GET_REQUEST_TABLE 0x2286 /* yields table of active requests */ 352 353 /* How to treat EINTR during SG_IO ioctl(), only in sg v3 and v4 driver */ 354 #define SG_SET_KEEP_ORPHAN 0x2287 /* 1 -> hold for read(), 0 -> drop (def) */ 355 #define SG_GET_KEEP_ORPHAN 0x2288 356 357 /* 358 * Yields scsi midlevel's access_count for this SCSI device. 20181014 No 359 * longer available, always yields 1. 360 */ 361 #define SG_GET_ACCESS_COUNT 0x2289 362 363 364 /* 365 * Default size (in bytes) a single scatter-gather list element can have. 366 * The value used by the driver is 'max(SG_SCATTER_SZ, PAGE_SIZE)'. This 367 * value should be a power of 2 (and may be rounded up internally). In the 368 * v4 driver this can be changed by ioctl(SG_SET_GET_EXTENDED{SGAT_ELEM_SZ}). 369 */ 370 #define SG_SCATTER_SZ (8 * 4096) 371 372 /* sg driver users' code should handle retries (e.g. from Unit Attentions) */ 373 #define SG_DEFAULT_RETRIES 0 374 375 /* Defaults, commented if they differ from original sg driver */ 376 #define SG_DEF_FORCE_PACK_ID 0 377 #define SG_DEF_KEEP_ORPHAN 0 378 #define SG_DEF_RESERVED_SIZE SG_SCATTER_SZ /* load time option */ 379 380 /* 381 * Maximum outstanding requests (i.e write()s without corresponding read()s) 382 * yields EDOM from write() if exceeded. This limit only applies prior to 383 * version 3.9 . It is still used as a maximum number of sg_req_info objects 384 * that are returned from the SG_GET_REQUEST_TABLE ioctl. 385 */ 386 #define SG_MAX_QUEUE 16 387 388 #define SG_BIG_BUFF SG_DEF_RESERVED_SIZE /* for backward compatibility */ 389 390 /* 391 * Alternate style type names, "..._t" variants (as found in the 392 * 'typedef struct * {};' definitions above) are preferred to these: 393 */ 394 typedef struct sg_io_hdr Sg_io_hdr; 395 typedef struct sg_io_vec Sg_io_vec; 396 typedef struct sg_scsi_id Sg_scsi_id; 397 typedef struct sg_req_info Sg_req_info; 398 399 400 /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */ 401 /* The v1+v2 SG interface based on the 'sg_header' structure follows. */ 402 /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ 403 404 #define SG_MAX_SENSE 16 /* this only applies to the sg_header interface */ 405 406 struct sg_header { 407 int pack_len; /* [o] reply_len (ie useless), ignored as input */ 408 int reply_len; /* [i] max length of expected reply (inc. sg_header) */ 409 int pack_id; /* [io] id number of packet (use ints >= 0) */ 410 int result; /* [o] 0==ok, else (+ve) Unix errno (best ignored) */ 411 unsigned int twelve_byte:1; 412 /* [i] Force 12 byte command length for group 6 & 7 commands */ 413 unsigned int target_status:5; /* [o] scsi status from target */ 414 unsigned int host_status:8; /* [o] host status (see "DID" codes) */ 415 unsigned int driver_status:8; /* [o] driver status+suggestion */ 416 unsigned int other_flags:10; /* unused */ 417 unsigned char sense_buffer[SG_MAX_SENSE]; 418 /* 419 * [o] Output in 3 cases: 420 * when target_status is CHECK_CONDITION or 421 * when target_status is COMMAND_TERMINATED or 422 * when (driver_status & DRIVER_SENSE) is true. 423 */ 424 }; 425 426 /* 427 * IOCTLs: The following are not required (or ignored) when the v3 or v4 428 * interface is used as those structures contain a timeout field. These 429 * ioctls are kept for backward compatibility with v1+v2 interfaces. 430 */ 431 432 #define SG_SET_TIMEOUT 0x2201 /* unit: (user space) jiffies */ 433 #define SG_GET_TIMEOUT 0x2202 /* yield timeout as _return_ value */ 434 435 /* 436 * Get/set command queuing state per fd (default is SG_DEF_COMMAND_Q. 437 * Each time a sg_io_hdr_t object is seen on this file descriptor, this 438 * command queuing flag is set on (overriding the previous setting). 439 * This setting defaults to 0 (i.e. no queuing) but gets set the first 440 * time that fd sees a v3 or v4 interface request. 441 */ 442 #define SG_GET_COMMAND_Q 0x2270 /* Yields 0 (queuing off) or 1 (on) */ 443 #define SG_SET_COMMAND_Q 0x2271 /* Change queuing state with 0 or 1 */ 444 445 /* 446 * Turn on/off error sense trace in the kernel log (1 and 0 respectively, default is 447 * off). 448 */ 449 #define SG_SET_DEBUG 0x227e /* 0 -> turn off debug */ 450 451 /* 452 * override SCSI command length with given number on the next write() on 453 * this file descriptor (v1 and v2 interface only) 454 */ 455 #define SG_NEXT_CMD_LEN 0x2283 456 457 /* 458 * New ioctls to replace async (non-blocking) write()/read() interface. 459 * Present in version 4 and later of the sg driver [>20190427]. The 460 * SG_IOSUBMIT_V3 and SG_IORECEIVE_V3 ioctls accept the sg_v3 interface 461 * based on struct sg_io_hdr shown above. The SG_IOSUBMIT and SG_IORECEIVE 462 * ioctls accept the sg_v4 interface based on struct sg_io_v4 found in 463 * <include/uapi/linux/bsg.h>. These objects are passed by a pointer in 464 * the third argument of the ioctl. 465 * 466 * Data may be transferred both from the user space to the driver by these 467 * ioctls. Hence the _IOWR macro is used here to generate the ioctl number 468 * rather than _IOW or _IOR. 469 */ 470 /* Submits a v4 interface object to driver, optionally receive tag back */ 471 #define SG_IOSUBMIT _IOWR(SG_IOCTL_MAGIC_NUM, 0x41, struct sg_io_v4) 472 473 /* Gives some v4 identifying info to driver, receives associated response */ 474 #define SG_IORECEIVE _IOWR(SG_IOCTL_MAGIC_NUM, 0x42, struct sg_io_v4) 475 476 /* Submits a v3 interface object to driver */ 477 #define SG_IOSUBMIT_V3 _IOWR(SG_IOCTL_MAGIC_NUM, 0x45, struct sg_io_hdr) 478 479 /* Gives some v3 identifying info to driver, receives associated response */ 480 #define SG_IORECEIVE_V3 _IOWR(SG_IOCTL_MAGIC_NUM, 0x46, struct sg_io_hdr) 481 482 /* Provides identifying info about a prior submission (e.g. a tag) */ 483 #define SG_IOABORT _IOW(SG_IOCTL_MAGIC_NUM, 0x43, struct sg_io_v4) 484 485 /* command queuing is always on when the v3 or v4 interface is used */ 486 #define SG_DEF_COMMAND_Q 0 487 488 #define SG_DEF_UNDERRUN_FLAG 0 489 490 /* If the timeout value in the v3_v4 interfaces is 0, this value is used */ 491 #define SG_DEFAULT_TIMEOUT (60*HZ) /* HZ == 'jiffies in 1 second' */ 492 493 #endif /* end of _UAPI_SCSI_SG_H guard */ 494