xref: /freebsd/sys/cam/cam_ccb.h (revision 07c6a62bab69296f2514dc99046ac701c4392f78)
1898b0535SWarner Losh /*-
28b8a9b1dSJustin T. Gibbs  * Data structures and definitions for CAM Control Blocks (CCBs).
38b8a9b1dSJustin T. Gibbs  *
44d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
5bec9534dSPedro F. Giffuni  *
68b8a9b1dSJustin T. Gibbs  * Copyright (c) 1997, 1998 Justin T. Gibbs.
78b8a9b1dSJustin T. Gibbs  * All rights reserved.
88b8a9b1dSJustin T. Gibbs  *
98b8a9b1dSJustin T. Gibbs  * Redistribution and use in source and binary forms, with or without
108b8a9b1dSJustin T. Gibbs  * modification, are permitted provided that the following conditions
118b8a9b1dSJustin T. Gibbs  * are met:
128b8a9b1dSJustin T. Gibbs  * 1. Redistributions of source code must retain the above copyright
138b8a9b1dSJustin T. Gibbs  *    notice, this list of conditions, and the following disclaimer,
148b8a9b1dSJustin T. Gibbs  *    without modification, immediately at the beginning of the file.
158b8a9b1dSJustin T. Gibbs  * 2. The name of the author may not be used to endorse or promote products
168b8a9b1dSJustin T. Gibbs  *    derived from this software without specific prior written permission.
178b8a9b1dSJustin T. Gibbs  *
188b8a9b1dSJustin T. Gibbs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
198b8a9b1dSJustin T. Gibbs  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
208b8a9b1dSJustin T. Gibbs  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
218b8a9b1dSJustin T. Gibbs  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
228b8a9b1dSJustin T. Gibbs  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
238b8a9b1dSJustin T. Gibbs  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
248b8a9b1dSJustin T. Gibbs  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
258b8a9b1dSJustin T. Gibbs  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
268b8a9b1dSJustin T. Gibbs  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
278b8a9b1dSJustin T. Gibbs  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
288b8a9b1dSJustin T. Gibbs  * SUCH DAMAGE.
298b8a9b1dSJustin T. Gibbs  */
308b8a9b1dSJustin T. Gibbs 
318b8a9b1dSJustin T. Gibbs #ifndef _CAM_CAM_CCB_H
328b8a9b1dSJustin T. Gibbs #define _CAM_CAM_CCB_H 1
338b8a9b1dSJustin T. Gibbs 
348b8a9b1dSJustin T. Gibbs #include <sys/queue.h>
3587cfaf0eSJustin T. Gibbs #include <sys/time.h>
36104a9b7eSAlexander Kabaev #include <sys/limits.h>
37c4473420SPeter Wemm #ifndef _KERNEL
388b8a9b1dSJustin T. Gibbs #include <sys/callout.h>
398b8a9b1dSJustin T. Gibbs #endif
408b8a9b1dSJustin T. Gibbs #include <cam/cam_debug.h>
418b8a9b1dSJustin T. Gibbs #include <cam/scsi/scsi_all.h>
4252c9ce25SScott Long #include <cam/ata/ata_all.h>
43baabaca3SWarner Losh #include <cam/nvme/nvme_all.h>
44a94a63f0SWarner Losh #include <cam/mmc/mmc_all.h>
458b8a9b1dSJustin T. Gibbs 
468b8a9b1dSJustin T. Gibbs /* General allocation length definitions for CCB structures */
478b8a9b1dSJustin T. Gibbs #define	IOCDBLEN	CAM_MAX_CDBLEN	/* Space for CDB bytes/pointer */
488b8a9b1dSJustin T. Gibbs #define	VUHBALEN	14		/* Vendor Unique HBA length */
498b8a9b1dSJustin T. Gibbs #define	SIM_IDLEN	16		/* ASCII string len for SIM ID */
508b8a9b1dSJustin T. Gibbs #define	HBA_IDLEN	16		/* ASCII string len for HBA ID */
518b8a9b1dSJustin T. Gibbs #define	DEV_IDLEN	16		/* ASCII string len for device names */
528b8a9b1dSJustin T. Gibbs #define CCB_PERIPH_PRIV_SIZE 	2	/* size of peripheral private area */
538b8a9b1dSJustin T. Gibbs #define CCB_SIM_PRIV_SIZE 	2	/* size of sim private area */
548b8a9b1dSJustin T. Gibbs 
558b8a9b1dSJustin T. Gibbs /* Struct definitions for CAM control blocks */
568b8a9b1dSJustin T. Gibbs 
578b8a9b1dSJustin T. Gibbs /* Common CCB header */
583394d423SEdward Tomasz Napierala 
593394d423SEdward Tomasz Napierala /* CCB memory allocation flags */
603394d423SEdward Tomasz Napierala typedef enum {
613394d423SEdward Tomasz Napierala 	CAM_CCB_FROM_UMA	= 0x00000001,/* CCB from a periph UMA zone */
623394d423SEdward Tomasz Napierala } ccb_alloc_flags;
633394d423SEdward Tomasz Napierala 
648b8a9b1dSJustin T. Gibbs /* CAM CCB flags */
658b8a9b1dSJustin T. Gibbs typedef enum {
668b8a9b1dSJustin T. Gibbs 	CAM_CDB_POINTER		= 0x00000001,/* The CDB field is a pointer    */
679ac30e0bSWarner Losh 	CAM_unused1		= 0x00000002,
689ac30e0bSWarner Losh 	CAM_unused2		= 0x00000004,
69dd5bac9dSJustin T. Gibbs 	CAM_NEGOTIATE		= 0x00000008,/*
70dd5bac9dSJustin T. Gibbs 					      * Perform transport negotiation
71dd5bac9dSJustin T. Gibbs 					      * with this command.
72dd5bac9dSJustin T. Gibbs 					      */
73dd0b4fb6SKonstantin Belousov 	CAM_DATA_ISPHYS		= 0x00000010,/* Data type with physical addrs */
748b8a9b1dSJustin T. Gibbs 	CAM_DIS_AUTOSENSE	= 0x00000020,/* Disable autosense feature     */
7506e79492SKenneth D. Merry 	CAM_DIR_BOTH		= 0x00000000,/* Data direction (00:IN/OUT)    */
768b8a9b1dSJustin T. Gibbs 	CAM_DIR_IN		= 0x00000040,/* Data direction (01:DATA IN)   */
778b8a9b1dSJustin T. Gibbs 	CAM_DIR_OUT		= 0x00000080,/* Data direction (10:DATA OUT)  */
788b8a9b1dSJustin T. Gibbs 	CAM_DIR_NONE		= 0x000000C0,/* Data direction (11:no data)   */
798b8a9b1dSJustin T. Gibbs 	CAM_DIR_MASK		= 0x000000C0,/* Data direction Mask	      */
80dd0b4fb6SKonstantin Belousov 	CAM_DATA_VADDR		= 0x00000000,/* Data type (000:Virtual)       */
81dd0b4fb6SKonstantin Belousov 	CAM_DATA_PADDR		= 0x00000010,/* Data type (001:Physical)      */
82dd0b4fb6SKonstantin Belousov 	CAM_DATA_SG		= 0x00040000,/* Data type (010:sglist)        */
83dd0b4fb6SKonstantin Belousov 	CAM_DATA_SG_PADDR	= 0x00040010,/* Data type (011:sglist phys)   */
84dd0b4fb6SKonstantin Belousov 	CAM_DATA_BIO		= 0x00200000,/* Data type (100:bio)           */
85dd0b4fb6SKonstantin Belousov 	CAM_DATA_MASK		= 0x00240010,/* Data type mask                */
869ac30e0bSWarner Losh 	CAM_unused3		= 0x00000100,
879ac30e0bSWarner Losh 	CAM_unused4		= 0x00000200,
888b8a9b1dSJustin T. Gibbs 	CAM_DEV_QFRZDIS		= 0x00000400,/* Disable DEV Q freezing	      */
898b8a9b1dSJustin T. Gibbs 	CAM_DEV_QFREEZE		= 0x00000800,/* Freeze DEV Q on execution     */
908b8a9b1dSJustin T. Gibbs 	CAM_HIGH_POWER		= 0x00001000,/* Command takes a lot of power  */
918b8a9b1dSJustin T. Gibbs 	CAM_SENSE_PTR		= 0x00002000,/* Sense data is a pointer	      */
928b8a9b1dSJustin T. Gibbs 	CAM_SENSE_PHYS		= 0x00004000,/* Sense pointer is physical addr*/
938b8a9b1dSJustin T. Gibbs 	CAM_TAG_ACTION_VALID	= 0x00008000,/* Use the tag action in this ccb*/
948b8a9b1dSJustin T. Gibbs 	CAM_PASS_ERR_RECOVER	= 0x00010000,/* Pass driver does err. recovery*/
958b8a9b1dSJustin T. Gibbs 	CAM_DIS_DISCONNECT	= 0x00020000,/* Disable disconnect	      */
969ac30e0bSWarner Losh 	CAM_unused5		= 0x00080000,
979ac30e0bSWarner Losh 	CAM_unused6		= 0x00100000,
988b8a9b1dSJustin T. Gibbs 	CAM_CDB_PHYS		= 0x00400000,/* CDB poiner is physical	      */
999ac30e0bSWarner Losh 	CAM_unused7		= 0x00800000,
1008b8a9b1dSJustin T. Gibbs 
1018b8a9b1dSJustin T. Gibbs /* Phase cognizant mode flags */
1029ac30e0bSWarner Losh 	CAM_unused8		= 0x01000000,
1039ac30e0bSWarner Losh 	CAM_unused9		= 0x02000000,
1049ac30e0bSWarner Losh 	CAM_unused10		= 0x04000000,
1059ac30e0bSWarner Losh 	CAM_unused11		= 0x08000000,
1069ac30e0bSWarner Losh 	CAM_unused12		= 0x10000000,
1079ac30e0bSWarner Losh 	CAM_unused13		= 0x20000000,
1089ac30e0bSWarner Losh 	CAM_unused14		= 0x40000000,
1098b8a9b1dSJustin T. Gibbs 
1108b8a9b1dSJustin T. Gibbs /* Host target Mode flags */
111826eb7c8SMatt Jacob 	CAM_SEND_SENSE		= 0x08000000,/* Send sense data with status   */
1129ac30e0bSWarner Losh 	CAM_unused15		= 0x10000000,
1139ac30e0bSWarner Losh 	CAM_unused16		= 0x20000000,
114227d67aaSAlexander Motin 	CAM_SEND_STATUS		= 0x40000000,/* Send status after data phase  */
115227d67aaSAlexander Motin 
116227d67aaSAlexander Motin 	CAM_UNLOCKED		= 0x80000000 /* Call callback without lock.   */
1178b8a9b1dSJustin T. Gibbs } ccb_flags;
1188b8a9b1dSJustin T. Gibbs 
119a9934668SKenneth D. Merry typedef enum {
12023d63288SKenneth D. Merry 	CAM_USER_DATA_ADDR	= 0x00000002,/* Userspace data pointers */
12123d63288SKenneth D. Merry 	CAM_SG_FORMAT_IOVEC	= 0x00000004,/* iovec instead of busdma S/G*/
122f053ca1fSConrad Meyer 	CAM_UNMAPPED_BUF	= 0x00000008 /* use unmapped I/O */
123a9934668SKenneth D. Merry } ccb_xflags;
124a9934668SKenneth D. Merry 
1258b8a9b1dSJustin T. Gibbs /* XPT Opcodes for xpt_action */
1268b8a9b1dSJustin T. Gibbs typedef enum {
1279deea857SKenneth D. Merry /* Function code flags are bits greater than 0xff */
1289deea857SKenneth D. Merry 	XPT_FC_QUEUED		= 0x100,
1299deea857SKenneth D. Merry 				/* Non-immediate function code */
1309deea857SKenneth D. Merry 	XPT_FC_USER_CCB		= 0x200,
1319deea857SKenneth D. Merry 	XPT_FC_XPT_ONLY		= 0x400,
1329deea857SKenneth D. Merry 				/* Only for the transport layer device */
133bf8bb7acSJustin T. Gibbs 	XPT_FC_DEV_QUEUED	= 0x800 | XPT_FC_QUEUED,
134bf8bb7acSJustin T. Gibbs 				/* Passes through the device queues */
1358b8a9b1dSJustin T. Gibbs /* Common function commands: 0x00->0x0F */
1369deea857SKenneth D. Merry 	XPT_NOOP 		= 0x00,
1379deea857SKenneth D. Merry 				/* Execute Nothing */
138bf8bb7acSJustin T. Gibbs 	XPT_SCSI_IO		= 0x01 | XPT_FC_DEV_QUEUED,
1399deea857SKenneth D. Merry 				/* Execute the requested I/O operation */
1409deea857SKenneth D. Merry 	XPT_GDEV_TYPE		= 0x02,
1419deea857SKenneth D. Merry 				/* Get type information for specified device */
1429deea857SKenneth D. Merry 	XPT_GDEVLIST		= 0x03,
1439deea857SKenneth D. Merry 				/* Get a list of peripheral devices */
1449deea857SKenneth D. Merry 	XPT_PATH_INQ		= 0x04,
1459deea857SKenneth D. Merry 				/* Path routing inquiry */
1469deea857SKenneth D. Merry 	XPT_REL_SIMQ		= 0x05,
14783c5d981SAlexander Motin 				/* Release a frozen device queue */
1489deea857SKenneth D. Merry 	XPT_SASYNC_CB		= 0x06,
1499deea857SKenneth D. Merry 				/* Set Asynchronous Callback Parameters */
1509deea857SKenneth D. Merry 	XPT_SDEV_TYPE		= 0x07,
1519deea857SKenneth D. Merry 				/* Set device type information */
1529deea857SKenneth D. Merry 	XPT_SCAN_BUS		= 0x08 | XPT_FC_QUEUED | XPT_FC_USER_CCB
1539deea857SKenneth D. Merry 				       | XPT_FC_XPT_ONLY,
1549deea857SKenneth D. Merry 				/* (Re)Scan the SCSI Bus */
1559deea857SKenneth D. Merry 	XPT_DEV_MATCH		= 0x09 | XPT_FC_XPT_ONLY,
1569deea857SKenneth D. Merry 				/* Get EDT entries matching the given pattern */
1579deea857SKenneth D. Merry 	XPT_DEBUG		= 0x0a,
1589deea857SKenneth D. Merry 				/* Turn on debugging for a bus, target or lun */
15987cfaf0eSJustin T. Gibbs 	XPT_PATH_STATS		= 0x0b,
16087cfaf0eSJustin T. Gibbs 				/* Path statistics (error counts, etc.) */
16187cfaf0eSJustin T. Gibbs 	XPT_GDEV_STATS		= 0x0c,
16287cfaf0eSJustin T. Gibbs 				/* Device statistics (error counts, etc.) */
1633501942bSJustin T. Gibbs 	XPT_DEV_ADVINFO		= 0x0e,
1643501942bSJustin T. Gibbs 				/* Get/Set Device advanced information */
165227d67aaSAlexander Motin 	XPT_ASYNC		= 0x0f | XPT_FC_QUEUED | XPT_FC_USER_CCB
166227d67aaSAlexander Motin 				       | XPT_FC_XPT_ONLY,
167227d67aaSAlexander Motin 				/* Asynchronous event */
1688b8a9b1dSJustin T. Gibbs /* SCSI Control Functions: 0x10->0x1F */
1699deea857SKenneth D. Merry 	XPT_ABORT		= 0x10,
1709deea857SKenneth D. Merry 				/* Abort the specified CCB */
1719deea857SKenneth D. Merry 	XPT_RESET_BUS		= 0x11 | XPT_FC_XPT_ONLY,
1729deea857SKenneth D. Merry 				/* Reset the specified SCSI bus */
173bf8bb7acSJustin T. Gibbs 	XPT_RESET_DEV		= 0x12 | XPT_FC_DEV_QUEUED,
1749deea857SKenneth D. Merry 				/* Bus Device Reset the specified SCSI device */
1759deea857SKenneth D. Merry 	XPT_TERM_IO		= 0x13,
1769deea857SKenneth D. Merry 				/* Terminate the I/O process */
1779deea857SKenneth D. Merry 	XPT_SCAN_LUN		= 0x14 | XPT_FC_QUEUED | XPT_FC_USER_CCB
1789deea857SKenneth D. Merry 				       | XPT_FC_XPT_ONLY,
1799deea857SKenneth D. Merry 				/* Scan Logical Unit */
1809deea857SKenneth D. Merry 	XPT_GET_TRAN_SETTINGS	= 0x15,
1819deea857SKenneth D. Merry 				/*
1828b8a9b1dSJustin T. Gibbs 				 * Get default/user transfer settings
1838b8a9b1dSJustin T. Gibbs 				 * for the target
1848b8a9b1dSJustin T. Gibbs 				 */
1859deea857SKenneth D. Merry 	XPT_SET_TRAN_SETTINGS	= 0x16,
1869deea857SKenneth D. Merry 				/*
1878b8a9b1dSJustin T. Gibbs 				 * Set transfer rate/width
1888b8a9b1dSJustin T. Gibbs 				 * negotiation settings
1898b8a9b1dSJustin T. Gibbs 				 */
1909deea857SKenneth D. Merry 	XPT_CALC_GEOMETRY	= 0x17,
1919deea857SKenneth D. Merry 				/*
1928b8a9b1dSJustin T. Gibbs 				 * Calculate the geometry parameters for
1938b8a9b1dSJustin T. Gibbs 				 * a device give the sector size and
1948b8a9b1dSJustin T. Gibbs 				 * volume size.
1958b8a9b1dSJustin T. Gibbs 				 */
19652c9ce25SScott Long 	XPT_ATA_IO		= 0x18 | XPT_FC_DEV_QUEUED,
19752c9ce25SScott Long 				/* Execute the requested ATA I/O operation */
1988b8a9b1dSJustin T. Gibbs 
199a2531862SWarner Losh 	XPT_GET_SIM_KNOB_OLD	= 0x18, /* Compat only */
2002df76c16SMatt Jacob 
2012df76c16SMatt Jacob 	XPT_SET_SIM_KNOB	= 0x19,
2022df76c16SMatt Jacob 				/*
2032df76c16SMatt Jacob 				 * Set SIM specific knob values.
2042df76c16SMatt Jacob 				 */
2050e85f214SMatt Jacob 
206a2531862SWarner Losh 	XPT_GET_SIM_KNOB	= 0x1a,
207a2531862SWarner Losh 				/*
208a2531862SWarner Losh 				 * Get SIM specific knob values.
209a2531862SWarner Losh 				 */
210a2531862SWarner Losh 
21106e79492SKenneth D. Merry 	XPT_SMP_IO		= 0x1b | XPT_FC_DEV_QUEUED,
21206e79492SKenneth D. Merry 				/* Serial Management Protocol */
21306e79492SKenneth D. Merry 
2147b05c3e3SWarner Losh 	XPT_NVME_IO		= 0x1c | XPT_FC_DEV_QUEUED,
215df424515SWarner Losh 				/* Execute the requested NVMe I/O operation */
2167b05c3e3SWarner Losh 
217a94a63f0SWarner Losh 	XPT_MMC_IO		= 0x1d | XPT_FC_DEV_QUEUED,
218bbb19fc7SWarner Losh 				/* Placeholder for MMC / SD / SDIO I/O stuff */
219bbb19fc7SWarner Losh 
220a94a63f0SWarner Losh 	XPT_SCAN_TGT		= 0x1e | XPT_FC_QUEUED | XPT_FC_USER_CCB
2210e85f214SMatt Jacob 				       | XPT_FC_XPT_ONLY,
2220e85f214SMatt Jacob 				/* Scan Target */
2230e85f214SMatt Jacob 
224df424515SWarner Losh 	XPT_NVME_ADMIN		= 0x1f | XPT_FC_DEV_QUEUED,
225df424515SWarner Losh 				/* Execute the requested NVMe Admin operation */
226df424515SWarner Losh 
2278b8a9b1dSJustin T. Gibbs /* HBA engine commands 0x20->0x2F */
2289deea857SKenneth D. Merry 	XPT_ENG_INQ		= 0x20 | XPT_FC_XPT_ONLY,
2299deea857SKenneth D. Merry 				/* HBA engine feature inquiry */
2303393f8daSKenneth D. Merry 	XPT_ENG_EXEC		= 0x21 | XPT_FC_DEV_QUEUED,
2319deea857SKenneth D. Merry 				/* HBA execute engine request */
2328b8a9b1dSJustin T. Gibbs 
2338b8a9b1dSJustin T. Gibbs /* Target mode commands: 0x30->0x3F */
2349deea857SKenneth D. Merry 	XPT_EN_LUN		= 0x30,
2359deea857SKenneth D. Merry 				/* Enable LUN as a target */
236bf8bb7acSJustin T. Gibbs 	XPT_TARGET_IO		= 0x31 | XPT_FC_DEV_QUEUED,
2379deea857SKenneth D. Merry 				/* Execute target I/O request */
2389deea857SKenneth D. Merry 	XPT_ACCEPT_TARGET_IO	= 0x32 | XPT_FC_QUEUED | XPT_FC_USER_CCB,
2399deea857SKenneth D. Merry 				/* Accept Host Target Mode CDB */
240bf8bb7acSJustin T. Gibbs 	XPT_CONT_TARGET_IO	= 0x33 | XPT_FC_DEV_QUEUED,
2419deea857SKenneth D. Merry 				/* Continue Host Target I/O Connection */
2429deea857SKenneth D. Merry 	XPT_IMMED_NOTIFY	= 0x34 | XPT_FC_QUEUED | XPT_FC_USER_CCB,
2432df76c16SMatt Jacob 				/* Notify Host Target driver of event (obsolete) */
2449deea857SKenneth D. Merry 	XPT_NOTIFY_ACK		= 0x35,
2452df76c16SMatt Jacob 				/* Acknowledgement of event (obsolete) */
2462df76c16SMatt Jacob 	XPT_IMMEDIATE_NOTIFY	= 0x36 | XPT_FC_QUEUED | XPT_FC_USER_CCB,
2472df76c16SMatt Jacob 				/* Notify Host Target driver of event */
2482df76c16SMatt Jacob 	XPT_NOTIFY_ACKNOWLEDGE	= 0x37 | XPT_FC_QUEUED | XPT_FC_USER_CCB,
2499deea857SKenneth D. Merry 				/* Acknowledgement of event */
250d68fae58SEdward Tomasz Napierala 	XPT_REPROBE_LUN		= 0x38 | XPT_FC_QUEUED | XPT_FC_USER_CCB,
251d68fae58SEdward Tomasz Napierala 				/* Query device capacity and notify GEOM */
2528b8a9b1dSJustin T. Gibbs 
253af2253f6SEmmanuel Vadot 	XPT_MMC_SET_TRAN_SETTINGS = 0x40 | XPT_FC_DEV_QUEUED,
254af2253f6SEmmanuel Vadot 	XPT_MMC_GET_TRAN_SETTINGS = 0x41 | XPT_FC_DEV_QUEUED,
255af2253f6SEmmanuel Vadot 
2568b8a9b1dSJustin T. Gibbs /* Vendor Unique codes: 0x80->0x8F */
2578b8a9b1dSJustin T. Gibbs 	XPT_VUNIQUE		= 0x80
2588b8a9b1dSJustin T. Gibbs } xpt_opcode;
2598b8a9b1dSJustin T. Gibbs 
2609deea857SKenneth D. Merry #define XPT_FC_GROUP_MASK		0xF0
2619deea857SKenneth D. Merry #define XPT_FC_GROUP(op) ((op) & XPT_FC_GROUP_MASK)
2629deea857SKenneth D. Merry #define XPT_FC_GROUP_COMMON		0x00
2639deea857SKenneth D. Merry #define XPT_FC_GROUP_SCSI_CONTROL	0x10
2649deea857SKenneth D. Merry #define XPT_FC_GROUP_HBA_ENGINE		0x20
2659deea857SKenneth D. Merry #define XPT_FC_GROUP_TMODE		0x30
2669deea857SKenneth D. Merry #define XPT_FC_GROUP_VENDOR_UNIQUE	0x80
267a89bb8b4SJustin T. Gibbs 
268bf8bb7acSJustin T. Gibbs #define XPT_FC_IS_DEV_QUEUED(ccb) 	\
269bf8bb7acSJustin T. Gibbs     (((ccb)->ccb_h.func_code & XPT_FC_DEV_QUEUED) == XPT_FC_DEV_QUEUED)
270bf8bb7acSJustin T. Gibbs #define XPT_FC_IS_QUEUED(ccb) 	\
271bf8bb7acSJustin T. Gibbs     (((ccb)->ccb_h.func_code & XPT_FC_QUEUED) != 0)
2723393f8daSKenneth D. Merry 
2733393f8daSKenneth D. Merry typedef enum {
2743393f8daSKenneth D. Merry 	PROTO_UNKNOWN,
2753393f8daSKenneth D. Merry 	PROTO_UNSPECIFIED,
2763393f8daSKenneth D. Merry 	PROTO_SCSI,	/* Small Computer System Interface */
2773393f8daSKenneth D. Merry 	PROTO_ATA,	/* AT Attachment */
2783393f8daSKenneth D. Merry 	PROTO_ATAPI,	/* AT Attachment Packetized Interface */
27952c9ce25SScott Long 	PROTO_SATAPM,	/* SATA Port Multiplier */
2803089bb2eSAlexander Motin 	PROTO_SEMB,	/* SATA Enclosure Management Bridge */
281baabaca3SWarner Losh 	PROTO_NVME,	/* NVME */
282a94a63f0SWarner Losh 	PROTO_MMCSD,	/* MMC, SD, SDIO */
2833393f8daSKenneth D. Merry } cam_proto;
2843393f8daSKenneth D. Merry 
2853393f8daSKenneth D. Merry typedef enum {
2863393f8daSKenneth D. Merry 	XPORT_UNKNOWN,
2873393f8daSKenneth D. Merry 	XPORT_UNSPECIFIED,
2883393f8daSKenneth D. Merry 	XPORT_SPI,	/* SCSI Parallel Interface */
2893393f8daSKenneth D. Merry 	XPORT_FC,	/* Fiber Channel */
2903393f8daSKenneth D. Merry 	XPORT_SSA,	/* Serial Storage Architecture */
2913393f8daSKenneth D. Merry 	XPORT_USB,	/* Universal Serial Bus */
2923393f8daSKenneth D. Merry 	XPORT_PPB,	/* Parallel Port Bus */
293c4270cb6SMatt Jacob 	XPORT_ATA,	/* AT Attachment */
294c4270cb6SMatt Jacob 	XPORT_SAS,	/* Serial Attached SCSI */
29552c9ce25SScott Long 	XPORT_SATA,	/* Serial AT Attachment */
29633ea30feSAlexander Motin 	XPORT_ISCSI,	/* iSCSI */
297b5595753SNathan Whitehorn 	XPORT_SRP,	/* SCSI RDMA Protocol */
298baabaca3SWarner Losh 	XPORT_NVME,	/* NVMe over PCIe */
299a94a63f0SWarner Losh 	XPORT_MMCSD,	/* MMC, SD, SDIO card */
300*07c6a62bSJohn Baldwin 	XPORT_NVMF,	/* NVMe over Fabrics */
3013393f8daSKenneth D. Merry } cam_xport;
3023393f8daSKenneth D. Merry 
303*07c6a62bSJohn Baldwin #define XPORT_IS_NVME(t)	((t) == XPORT_NVME || (t) == XPORT_NVMF)
304b8b6b5d3SAlexander Motin #define XPORT_IS_ATA(t)		((t) == XPORT_ATA || (t) == XPORT_SATA)
305b8b6b5d3SAlexander Motin #define XPORT_IS_SCSI(t)	((t) != XPORT_UNKNOWN && \
306b8b6b5d3SAlexander Motin 				 (t) != XPORT_UNSPECIFIED && \
307336b7b66SWarner Losh 				 !XPORT_IS_ATA(t) && !XPORT_IS_NVME(t))
308b8b6b5d3SAlexander Motin #define XPORT_DEVSTAT_TYPE(t)	(XPORT_IS_ATA(t) ? DEVSTAT_TYPE_IF_IDE : \
309b8b6b5d3SAlexander Motin 				 XPORT_IS_SCSI(t) ? DEVSTAT_TYPE_IF_SCSI : \
310d282baddSAlexander Motin 				 XPORT_IS_NVME(t) ? DEVSTAT_TYPE_IF_NVME : \
311b8b6b5d3SAlexander Motin 				 DEVSTAT_TYPE_IF_OTHER)
312b8b6b5d3SAlexander Motin 
3133393f8daSKenneth D. Merry #define PROTO_VERSION_UNKNOWN (UINT_MAX - 1)
3143393f8daSKenneth D. Merry #define PROTO_VERSION_UNSPECIFIED UINT_MAX
3153393f8daSKenneth D. Merry #define XPORT_VERSION_UNKNOWN (UINT_MAX - 1)
3163393f8daSKenneth D. Merry #define XPORT_VERSION_UNSPECIFIED UINT_MAX
3173393f8daSKenneth D. Merry 
3188b8a9b1dSJustin T. Gibbs typedef union {
319e3975643SJake Burkholder 	LIST_ENTRY(ccb_hdr) le;
320e3975643SJake Burkholder 	SLIST_ENTRY(ccb_hdr) sle;
321e3975643SJake Burkholder 	TAILQ_ENTRY(ccb_hdr) tqe;
322e3975643SJake Burkholder 	STAILQ_ENTRY(ccb_hdr) stqe;
3238b8a9b1dSJustin T. Gibbs } camq_entry;
3248b8a9b1dSJustin T. Gibbs 
3258b8a9b1dSJustin T. Gibbs typedef union {
3268b8a9b1dSJustin T. Gibbs 	void		*ptr;
3278b8a9b1dSJustin T. Gibbs 	u_long		field;
3287af2f2c8SWarner Losh 	uint8_t	bytes[sizeof(uintptr_t)];
3298b8a9b1dSJustin T. Gibbs } ccb_priv_entry;
3308b8a9b1dSJustin T. Gibbs 
3318b8a9b1dSJustin T. Gibbs typedef union {
3328b8a9b1dSJustin T. Gibbs 	ccb_priv_entry	entries[CCB_PERIPH_PRIV_SIZE];
3337af2f2c8SWarner Losh 	uint8_t	bytes[CCB_PERIPH_PRIV_SIZE * sizeof(ccb_priv_entry)];
3348b8a9b1dSJustin T. Gibbs } ccb_ppriv_area;
3358b8a9b1dSJustin T. Gibbs 
3368b8a9b1dSJustin T. Gibbs typedef union {
3378b8a9b1dSJustin T. Gibbs 	ccb_priv_entry	entries[CCB_SIM_PRIV_SIZE];
3387af2f2c8SWarner Losh 	uint8_t	bytes[CCB_SIM_PRIV_SIZE * sizeof(ccb_priv_entry)];
3398b8a9b1dSJustin T. Gibbs } ccb_spriv_area;
3408b8a9b1dSJustin T. Gibbs 
341f564de00SScott Long typedef struct {
342f564de00SScott Long 	struct timeval	*etime;
343f564de00SScott Long 	uintptr_t	sim_data;
344f564de00SScott Long 	uintptr_t	periph_data;
345f564de00SScott Long } ccb_qos_area;
346f564de00SScott Long 
3478b8a9b1dSJustin T. Gibbs struct ccb_hdr {
3488b8a9b1dSJustin T. Gibbs 	cam_pinfo	pinfo;		/* Info for priority scheduling */
3498b8a9b1dSJustin T. Gibbs 	camq_entry	xpt_links;	/* For chaining in the XPT layer */
3508b8a9b1dSJustin T. Gibbs 	camq_entry	sim_links;	/* For chaining in the SIM layer */
3518b8a9b1dSJustin T. Gibbs 	camq_entry	periph_links;	/* For chaining in the type driver */
3523394d423SEdward Tomasz Napierala #if BYTE_ORDER == LITTLE_ENDIAN
3537af2f2c8SWarner Losh 	uint16_t       retry_count;
3547af2f2c8SWarner Losh 	uint16_t       alloc_flags;	/* ccb_alloc_flags */
3553394d423SEdward Tomasz Napierala #else
3567af2f2c8SWarner Losh 	uint16_t       alloc_flags;	/* ccb_alloc_flags */
3577af2f2c8SWarner Losh 	uint16_t       retry_count;
3583394d423SEdward Tomasz Napierala #endif
3598b8a9b1dSJustin T. Gibbs 	void		(*cbfcnp)(struct cam_periph *, union ccb *);
360af693a70SScott Long 					/* Callback on completion function */
3618b8a9b1dSJustin T. Gibbs 	xpt_opcode	func_code;	/* XPT function code */
3627af2f2c8SWarner Losh 	uint32_t	status;		/* Status returned by CAM subsystem */
363af693a70SScott Long 	struct		cam_path *path;	/* Compiled path for this ccb */
3648b8a9b1dSJustin T. Gibbs 	path_id_t	path_id;	/* Path ID for the request */
3658b8a9b1dSJustin T. Gibbs 	target_id_t	target_id;	/* Target device ID */
3668b8a9b1dSJustin T. Gibbs 	lun_id_t	target_lun;	/* Target LUN number */
3677af2f2c8SWarner Losh 	uint32_t	flags;		/* ccb_flags */
3687af2f2c8SWarner Losh 	uint32_t	xflags;		/* Extended flags */
3698b8a9b1dSJustin T. Gibbs 	ccb_ppriv_area	periph_priv;
3708b8a9b1dSJustin T. Gibbs 	ccb_spriv_area	sim_priv;
371f564de00SScott Long 	ccb_qos_area	qos;
3727af2f2c8SWarner Losh 	uint32_t	timeout;	/* Hard timeout value in mseconds */
373f564de00SScott Long 	struct timeval	softtimeout;	/* Soft timeout value in sec + usec */
3748b8a9b1dSJustin T. Gibbs };
3758b8a9b1dSJustin T. Gibbs 
3768b8a9b1dSJustin T. Gibbs /* Get Device Information CCB */
3778b8a9b1dSJustin T. Gibbs struct ccb_getdev {
3788b8a9b1dSJustin T. Gibbs 	struct	  ccb_hdr ccb_h;
37952c9ce25SScott Long 	cam_proto protocol;
3808b8a9b1dSJustin T. Gibbs 	struct scsi_inquiry_data inq_data;
38152c9ce25SScott Long 	struct ata_params ident_data;
3827af2f2c8SWarner Losh 	uint8_t  serial_num[252];
3837af2f2c8SWarner Losh 	uint8_t  inq_flags;
3847af2f2c8SWarner Losh 	uint8_t  serial_num_len;
3859f8ed7e4SWarner Losh 	void *padding[2];
3868b8a9b1dSJustin T. Gibbs };
3878b8a9b1dSJustin T. Gibbs 
38887cfaf0eSJustin T. Gibbs /* Device Statistics CCB */
38987cfaf0eSJustin T. Gibbs struct ccb_getdevstats {
39087cfaf0eSJustin T. Gibbs 	struct	ccb_hdr	ccb_h;
39187cfaf0eSJustin T. Gibbs 	int	dev_openings;	/* Space left for more work on device*/
39287cfaf0eSJustin T. Gibbs 	int	dev_active;	/* Transactions running on the device */
393959ec258SAlexander Motin 	int	allocated;	/* CCBs allocated for the device */
394959ec258SAlexander Motin 	int	queued;		/* CCBs queued to be sent to the device */
39587cfaf0eSJustin T. Gibbs 	int	held;		/*
39687cfaf0eSJustin T. Gibbs 				 * CCBs held by peripheral drivers
39787cfaf0eSJustin T. Gibbs 				 * for this device
39887cfaf0eSJustin T. Gibbs 				 */
39982815562SJustin T. Gibbs 	int	maxtags;	/*
40082815562SJustin T. Gibbs 				 * Boundary conditions for number of
40182815562SJustin T. Gibbs 				 * tagged operations
40282815562SJustin T. Gibbs 				 */
40382815562SJustin T. Gibbs 	int	mintags;
40487cfaf0eSJustin T. Gibbs 	struct	timeval last_reset;	/* Time of last bus reset/loop init */
40587cfaf0eSJustin T. Gibbs };
4068b8a9b1dSJustin T. Gibbs 
4078b8a9b1dSJustin T. Gibbs typedef enum {
4088b8a9b1dSJustin T. Gibbs 	CAM_GDEVLIST_LAST_DEVICE,
4098b8a9b1dSJustin T. Gibbs 	CAM_GDEVLIST_LIST_CHANGED,
4108b8a9b1dSJustin T. Gibbs 	CAM_GDEVLIST_MORE_DEVS,
4118b8a9b1dSJustin T. Gibbs 	CAM_GDEVLIST_ERROR
4128b8a9b1dSJustin T. Gibbs } ccb_getdevlist_status_e;
4138b8a9b1dSJustin T. Gibbs 
4148b8a9b1dSJustin T. Gibbs struct ccb_getdevlist {
4158b8a9b1dSJustin T. Gibbs 	struct ccb_hdr		ccb_h;
4168b8a9b1dSJustin T. Gibbs 	char 			periph_name[DEV_IDLEN];
4177af2f2c8SWarner Losh 	uint32_t		unit_number;
4188b8a9b1dSJustin T. Gibbs 	unsigned int		generation;
4197af2f2c8SWarner Losh 	uint32_t		index;
4208b8a9b1dSJustin T. Gibbs 	ccb_getdevlist_status_e	status;
4218b8a9b1dSJustin T. Gibbs };
4228b8a9b1dSJustin T. Gibbs 
4238b8a9b1dSJustin T. Gibbs typedef enum {
4248f9be1eeSAlexander Motin 	PERIPH_MATCH_ANY	= 0x000,
4258b8a9b1dSJustin T. Gibbs 	PERIPH_MATCH_PATH	= 0x001,
4268b8a9b1dSJustin T. Gibbs 	PERIPH_MATCH_TARGET	= 0x002,
4278b8a9b1dSJustin T. Gibbs 	PERIPH_MATCH_LUN	= 0x004,
4288b8a9b1dSJustin T. Gibbs 	PERIPH_MATCH_NAME	= 0x008,
4298b8a9b1dSJustin T. Gibbs 	PERIPH_MATCH_UNIT	= 0x010,
4308b8a9b1dSJustin T. Gibbs } periph_pattern_flags;
4318b8a9b1dSJustin T. Gibbs 
4328b8a9b1dSJustin T. Gibbs struct periph_match_pattern {
4338b8a9b1dSJustin T. Gibbs 	char			periph_name[DEV_IDLEN];
4347af2f2c8SWarner Losh 	uint32_t		unit_number;
4358b8a9b1dSJustin T. Gibbs 	path_id_t		path_id;
4368b8a9b1dSJustin T. Gibbs 	target_id_t		target_id;
4378b8a9b1dSJustin T. Gibbs 	lun_id_t		target_lun;
4388b8a9b1dSJustin T. Gibbs 	periph_pattern_flags	flags;
4398b8a9b1dSJustin T. Gibbs };
4408b8a9b1dSJustin T. Gibbs 
4418b8a9b1dSJustin T. Gibbs typedef enum {
4428f9be1eeSAlexander Motin 	DEV_MATCH_ANY		= 0x000,
4438b8a9b1dSJustin T. Gibbs 	DEV_MATCH_PATH		= 0x001,
4448b8a9b1dSJustin T. Gibbs 	DEV_MATCH_TARGET	= 0x002,
4458b8a9b1dSJustin T. Gibbs 	DEV_MATCH_LUN		= 0x004,
4468b8a9b1dSJustin T. Gibbs 	DEV_MATCH_INQUIRY	= 0x008,
4473501942bSJustin T. Gibbs 	DEV_MATCH_DEVID		= 0x010,
4488b8a9b1dSJustin T. Gibbs } dev_pattern_flags;
4498b8a9b1dSJustin T. Gibbs 
4503501942bSJustin T. Gibbs struct device_id_match_pattern {
4513501942bSJustin T. Gibbs 	uint8_t id_len;
4523501942bSJustin T. Gibbs 	uint8_t id[256];
4533501942bSJustin T. Gibbs };
4543501942bSJustin T. Gibbs 
4558b8a9b1dSJustin T. Gibbs struct device_match_pattern {
4568b8a9b1dSJustin T. Gibbs 	path_id_t					path_id;
4578b8a9b1dSJustin T. Gibbs 	target_id_t					target_id;
4588b8a9b1dSJustin T. Gibbs 	lun_id_t					target_lun;
4598b8a9b1dSJustin T. Gibbs 	dev_pattern_flags				flags;
4603501942bSJustin T. Gibbs 	union {
4613501942bSJustin T. Gibbs 		struct scsi_static_inquiry_pattern	inq_pat;
4623501942bSJustin T. Gibbs 		struct device_id_match_pattern		devid_pat;
4633501942bSJustin T. Gibbs 	} data;
4648b8a9b1dSJustin T. Gibbs };
4658b8a9b1dSJustin T. Gibbs 
4668b8a9b1dSJustin T. Gibbs typedef enum {
4678f9be1eeSAlexander Motin 	BUS_MATCH_ANY		= 0x000,
4688b8a9b1dSJustin T. Gibbs 	BUS_MATCH_PATH		= 0x001,
4698b8a9b1dSJustin T. Gibbs 	BUS_MATCH_NAME		= 0x002,
4708b8a9b1dSJustin T. Gibbs 	BUS_MATCH_UNIT		= 0x004,
4718b8a9b1dSJustin T. Gibbs 	BUS_MATCH_BUS_ID	= 0x008,
4728b8a9b1dSJustin T. Gibbs } bus_pattern_flags;
4738b8a9b1dSJustin T. Gibbs 
4748b8a9b1dSJustin T. Gibbs struct bus_match_pattern {
4758b8a9b1dSJustin T. Gibbs 	path_id_t		path_id;
4768b8a9b1dSJustin T. Gibbs 	char			dev_name[DEV_IDLEN];
4777af2f2c8SWarner Losh 	uint32_t		unit_number;
4787af2f2c8SWarner Losh 	uint32_t		bus_id;
4798b8a9b1dSJustin T. Gibbs 	bus_pattern_flags	flags;
4808b8a9b1dSJustin T. Gibbs };
4818b8a9b1dSJustin T. Gibbs 
4828b8a9b1dSJustin T. Gibbs union match_pattern {
4838b8a9b1dSJustin T. Gibbs 	struct periph_match_pattern	periph_pattern;
4848b8a9b1dSJustin T. Gibbs 	struct device_match_pattern	device_pattern;
4858b8a9b1dSJustin T. Gibbs 	struct bus_match_pattern	bus_pattern;
4868b8a9b1dSJustin T. Gibbs };
4878b8a9b1dSJustin T. Gibbs 
4888b8a9b1dSJustin T. Gibbs typedef enum {
4898b8a9b1dSJustin T. Gibbs 	DEV_MATCH_PERIPH,
4908b8a9b1dSJustin T. Gibbs 	DEV_MATCH_DEVICE,
4918b8a9b1dSJustin T. Gibbs 	DEV_MATCH_BUS
4928b8a9b1dSJustin T. Gibbs } dev_match_type;
4938b8a9b1dSJustin T. Gibbs 
4948b8a9b1dSJustin T. Gibbs struct dev_match_pattern {
4958b8a9b1dSJustin T. Gibbs 	dev_match_type		type;
4968b8a9b1dSJustin T. Gibbs 	union match_pattern	pattern;
4978b8a9b1dSJustin T. Gibbs };
4988b8a9b1dSJustin T. Gibbs 
4998b8a9b1dSJustin T. Gibbs struct periph_match_result {
5008b8a9b1dSJustin T. Gibbs 	char			periph_name[DEV_IDLEN];
5017af2f2c8SWarner Losh 	uint32_t		unit_number;
5028b8a9b1dSJustin T. Gibbs 	path_id_t		path_id;
5038b8a9b1dSJustin T. Gibbs 	target_id_t		target_id;
5048b8a9b1dSJustin T. Gibbs 	lun_id_t		target_lun;
5058b8a9b1dSJustin T. Gibbs };
5068b8a9b1dSJustin T. Gibbs 
5079deea857SKenneth D. Merry typedef enum {
5089deea857SKenneth D. Merry 	DEV_RESULT_NOFLAG		= 0x00,
5099deea857SKenneth D. Merry 	DEV_RESULT_UNCONFIGURED		= 0x01
5109deea857SKenneth D. Merry } dev_result_flags;
5119deea857SKenneth D. Merry 
5128b8a9b1dSJustin T. Gibbs struct device_match_result {
5138b8a9b1dSJustin T. Gibbs 	path_id_t			path_id;
5148b8a9b1dSJustin T. Gibbs 	target_id_t			target_id;
5158b8a9b1dSJustin T. Gibbs 	lun_id_t			target_lun;
51652c9ce25SScott Long 	cam_proto			protocol;
5178b8a9b1dSJustin T. Gibbs 	struct scsi_inquiry_data	inq_data;
51852c9ce25SScott Long 	struct ata_params		ident_data;
5199deea857SKenneth D. Merry 	dev_result_flags		flags;
5208b8a9b1dSJustin T. Gibbs };
5218b8a9b1dSJustin T. Gibbs 
5228b8a9b1dSJustin T. Gibbs struct bus_match_result {
5238b8a9b1dSJustin T. Gibbs 	path_id_t	path_id;
5248b8a9b1dSJustin T. Gibbs 	char		dev_name[DEV_IDLEN];
5257af2f2c8SWarner Losh 	uint32_t	unit_number;
5267af2f2c8SWarner Losh 	uint32_t	bus_id;
5278b8a9b1dSJustin T. Gibbs };
5288b8a9b1dSJustin T. Gibbs 
5298b8a9b1dSJustin T. Gibbs union match_result {
5308b8a9b1dSJustin T. Gibbs 	struct periph_match_result	periph_result;
5318b8a9b1dSJustin T. Gibbs 	struct device_match_result	device_result;
5328b8a9b1dSJustin T. Gibbs 	struct bus_match_result		bus_result;
5338b8a9b1dSJustin T. Gibbs };
5348b8a9b1dSJustin T. Gibbs 
5358b8a9b1dSJustin T. Gibbs struct dev_match_result {
5368b8a9b1dSJustin T. Gibbs 	dev_match_type		type;
5378b8a9b1dSJustin T. Gibbs 	union match_result	result;
5388b8a9b1dSJustin T. Gibbs };
5398b8a9b1dSJustin T. Gibbs 
5408b8a9b1dSJustin T. Gibbs typedef enum {
5418b8a9b1dSJustin T. Gibbs 	CAM_DEV_MATCH_LAST,
5428b8a9b1dSJustin T. Gibbs 	CAM_DEV_MATCH_MORE,
5438b8a9b1dSJustin T. Gibbs 	CAM_DEV_MATCH_LIST_CHANGED,
5448b8a9b1dSJustin T. Gibbs 	CAM_DEV_MATCH_SIZE_ERROR,
5458b8a9b1dSJustin T. Gibbs 	CAM_DEV_MATCH_ERROR
5468b8a9b1dSJustin T. Gibbs } ccb_dev_match_status;
5478b8a9b1dSJustin T. Gibbs 
5488b8a9b1dSJustin T. Gibbs typedef enum {
5498b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_NONE	= 0x000,
5508b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_BUS		= 0x001,
5518b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_TARGET	= 0x002,
5528b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_DEVICE	= 0x004,
5538b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_PERIPH	= 0x008,
5548b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_PDPTR	= 0x010,
5558b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_TYPEMASK	= 0xf00,
5568b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_EDT		= 0x100,
5578b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_PDRV	= 0x200
5588b8a9b1dSJustin T. Gibbs } dev_pos_type;
5598b8a9b1dSJustin T. Gibbs 
5608b8a9b1dSJustin T. Gibbs struct ccb_dm_cookie {
5618b8a9b1dSJustin T. Gibbs 	void 	*bus;
5628b8a9b1dSJustin T. Gibbs 	void	*target;
5638b8a9b1dSJustin T. Gibbs 	void	*device;
5648b8a9b1dSJustin T. Gibbs 	void	*periph;
5658b8a9b1dSJustin T. Gibbs 	void	*pdrv;
5668b8a9b1dSJustin T. Gibbs };
5678b8a9b1dSJustin T. Gibbs 
5688b8a9b1dSJustin T. Gibbs struct ccb_dev_position {
5698b8a9b1dSJustin T. Gibbs 	u_int			generations[4];
5708b8a9b1dSJustin T. Gibbs #define	CAM_BUS_GENERATION	0x00
5718b8a9b1dSJustin T. Gibbs #define CAM_TARGET_GENERATION	0x01
5728b8a9b1dSJustin T. Gibbs #define CAM_DEV_GENERATION	0x02
5738b8a9b1dSJustin T. Gibbs #define CAM_PERIPH_GENERATION	0x03
5748b8a9b1dSJustin T. Gibbs 	dev_pos_type		position_type;
5758b8a9b1dSJustin T. Gibbs 	struct ccb_dm_cookie	cookie;
5768b8a9b1dSJustin T. Gibbs };
5778b8a9b1dSJustin T. Gibbs 
5788b8a9b1dSJustin T. Gibbs struct ccb_dev_match {
5798b8a9b1dSJustin T. Gibbs 	struct ccb_hdr			ccb_h;
5808b8a9b1dSJustin T. Gibbs 	ccb_dev_match_status		status;
5817af2f2c8SWarner Losh 	uint32_t			num_patterns;
5827af2f2c8SWarner Losh 	uint32_t			pattern_buf_len;
5838b8a9b1dSJustin T. Gibbs 	struct dev_match_pattern	*patterns;
5847af2f2c8SWarner Losh 	uint32_t			num_matches;
5857af2f2c8SWarner Losh 	uint32_t			match_buf_len;
5868b8a9b1dSJustin T. Gibbs 	struct dev_match_result		*matches;
5878b8a9b1dSJustin T. Gibbs 	struct ccb_dev_position		pos;
5888b8a9b1dSJustin T. Gibbs };
5898b8a9b1dSJustin T. Gibbs 
5908b8a9b1dSJustin T. Gibbs /*
5918b8a9b1dSJustin T. Gibbs  * Definitions for the path inquiry CCB fields.
5928b8a9b1dSJustin T. Gibbs  */
5938f9be1eeSAlexander Motin #define CAM_VERSION	0x1a	/* Hex value for current version */
5948b8a9b1dSJustin T. Gibbs 
5958b8a9b1dSJustin T. Gibbs typedef enum {
5968b8a9b1dSJustin T. Gibbs 	PI_MDP_ABLE	= 0x80,	/* Supports MDP message */
5978b8a9b1dSJustin T. Gibbs 	PI_WIDE_32	= 0x40,	/* Supports 32 bit wide SCSI */
5988b8a9b1dSJustin T. Gibbs 	PI_WIDE_16	= 0x20, /* Supports 16 bit wide SCSI */
5998b8a9b1dSJustin T. Gibbs 	PI_SDTR_ABLE	= 0x10,	/* Supports SDTR message */
6008b8a9b1dSJustin T. Gibbs 	PI_LINKED_CDB	= 0x08, /* Supports linked CDBs */
60152c9ce25SScott Long 	PI_SATAPM	= 0x04,	/* Supports SATA PM */
6028b8a9b1dSJustin T. Gibbs 	PI_TAG_ABLE	= 0x02,	/* Supports tag queue messages */
603273a1a3dSKenneth D. Merry 	PI_SOFT_RST	= 0x01	/* Supports soft reset alternative */
6048b8a9b1dSJustin T. Gibbs } pi_inqflag;
6058b8a9b1dSJustin T. Gibbs 
6068b8a9b1dSJustin T. Gibbs typedef enum {
6078b8a9b1dSJustin T. Gibbs 	PIT_PROCESSOR	= 0x80,	/* Target mode processor mode */
6088b8a9b1dSJustin T. Gibbs 	PIT_PHASE	= 0x40,	/* Target mode phase cog. mode */
6098b8a9b1dSJustin T. Gibbs 	PIT_DISCONNECT	= 0x20,	/* Disconnects supported in target mode */
6108b8a9b1dSJustin T. Gibbs 	PIT_TERM_IO	= 0x10,	/* Terminate I/O message supported in TM */
6118b8a9b1dSJustin T. Gibbs 	PIT_GRP_6	= 0x08,	/* Group 6 commands supported */
612273a1a3dSKenneth D. Merry 	PIT_GRP_7	= 0x04	/* Group 7 commands supported */
6138b8a9b1dSJustin T. Gibbs } pi_tmflag;
6148b8a9b1dSJustin T. Gibbs 
6158b8a9b1dSJustin T. Gibbs typedef enum {
616916d57dfSWarner Losh 	PIM_ATA_EXT	= 0x200,/* ATA requests can understand ata_ext requests */
617f564de00SScott Long 	PIM_EXTLUNS	= 0x100,/* 64bit extended LUNs supported */
6188b8a9b1dSJustin T. Gibbs 	PIM_SCANHILO	= 0x80,	/* Bus scans from high ID to low ID */
6198b8a9b1dSJustin T. Gibbs 	PIM_NOREMOVE	= 0x40,	/* Removeable devices not included in scan */
62098192658SJustin T. Gibbs 	PIM_NOINITIATOR	= 0x20,	/* Initiator role not supported. */
6211deac581SNate Lawson 	PIM_NOBUSRESET	= 0x10,	/* User has disabled initial BUS RESET */
622c1c3139eSMatt Jacob 	PIM_NO_6_BYTE	= 0x08,	/* Do not send 6-byte commands */
623abc1e60eSKonstantin Belousov 	PIM_SEQSCAN	= 0x04,	/* Do bus scans sequentially, not in parallel */
624abc1e60eSKonstantin Belousov 	PIM_UNMAPPED	= 0x02,
625b01773b0SKenneth D. Merry 	PIM_NOSCAN	= 0x01	/* SIM does its own scanning */
6268b8a9b1dSJustin T. Gibbs } pi_miscflag;
6278b8a9b1dSJustin T. Gibbs 
6288b8a9b1dSJustin T. Gibbs /* Path Inquiry CCB */
6293393f8daSKenneth D. Merry struct ccb_pathinq_settings_spi {
6307af2f2c8SWarner Losh 	uint8_t ppr_options;
6313393f8daSKenneth D. Merry };
6322df76c16SMatt Jacob 
633fd13aa47SMatt Jacob struct ccb_pathinq_settings_fc {
6347af2f2c8SWarner Losh 	uint64_t wwnn;		/* world wide node name */
6357af2f2c8SWarner Losh 	uint64_t wwpn;		/* world wide port name */
6367af2f2c8SWarner Losh 	uint32_t port;		/* 24 bit port id, if known */
6377af2f2c8SWarner Losh 	uint32_t bitrate;	/* Mbps */
638fd13aa47SMatt Jacob };
6392df76c16SMatt Jacob 
640c4270cb6SMatt Jacob struct ccb_pathinq_settings_sas {
6417af2f2c8SWarner Losh 	uint32_t bitrate;	/* Mbps */
642c4270cb6SMatt Jacob };
643f24c011bSWarner Losh 
644027d0612SWarner Losh #define NVME_DEV_NAME_LEN	52
645f24c011bSWarner Losh struct ccb_pathinq_settings_nvme {
646c2005bbaSWarner Losh 	uint32_t nsid;		/* Namespace ID for this path */
6474484c8f5SWarner Losh 	uint32_t domain;
6484484c8f5SWarner Losh 	uint8_t  bus;
6494484c8f5SWarner Losh 	uint8_t  slot;
6504484c8f5SWarner Losh 	uint8_t  function;
6514484c8f5SWarner Losh 	uint8_t  extra;
652027d0612SWarner Losh 	char	 dev_name[NVME_DEV_NAME_LEN]; /* nvme controller dev name for this device */
653f24c011bSWarner Losh };
654027d0612SWarner Losh _Static_assert(sizeof(struct ccb_pathinq_settings_nvme) == 64,
655027d0612SWarner Losh     "ccb_pathinq_settings_nvme too big");
656f24c011bSWarner Losh 
657*07c6a62bSJohn Baldwin struct ccb_pathinq_settings_nvmf {
658*07c6a62bSJohn Baldwin 	uint32_t nsid;		/* Namespace ID for this path */
659*07c6a62bSJohn Baldwin 	uint8_t  trtype;
660*07c6a62bSJohn Baldwin 	char	 dev_name[NVME_DEV_NAME_LEN]; /* nvme controller dev name for this device */
661*07c6a62bSJohn Baldwin };
662*07c6a62bSJohn Baldwin 
663fd13aa47SMatt Jacob #define	PATHINQ_SETTINGS_SIZE	128
6643393f8daSKenneth D. Merry 
6658b8a9b1dSJustin T. Gibbs struct ccb_pathinq {
6668b8a9b1dSJustin T. Gibbs 	struct 	    ccb_hdr ccb_h;
6677af2f2c8SWarner Losh 	uint8_t    version_num;	/* Version number for the SIM/HBA */
6687af2f2c8SWarner Losh 	uint8_t    hba_inquiry;	/* Mimic of INQ byte 7 for the HBA */
6697af2f2c8SWarner Losh 	uint16_t   target_sprt;	/* Flags for target mode support */
6707af2f2c8SWarner Losh 	uint32_t   hba_misc;		/* Misc HBA features */
6717af2f2c8SWarner Losh 	uint16_t   hba_eng_cnt;	/* HBA engine count */
6728b8a9b1dSJustin T. Gibbs 					/* Vendor Unique capabilities */
6737af2f2c8SWarner Losh 	uint8_t    vuhba_flags[VUHBALEN];
6747af2f2c8SWarner Losh 	uint32_t   max_target;		/* Maximum supported Target */
6757af2f2c8SWarner Losh 	uint32_t   max_lun;		/* Maximum supported Lun */
6767af2f2c8SWarner Losh 	uint32_t   async_flags;	/* Installed Async handlers */
6778b8a9b1dSJustin T. Gibbs 	path_id_t   hpath_id;		/* Highest Path ID in the subsystem */
6788b8a9b1dSJustin T. Gibbs 	target_id_t initiator_id;	/* ID of the HBA on the SCSI bus */
6798b8a9b1dSJustin T. Gibbs 	char	    sim_vid[SIM_IDLEN];	/* Vendor ID of the SIM */
6808b8a9b1dSJustin T. Gibbs 	char	    hba_vid[HBA_IDLEN];	/* Vendor ID of the HBA */
6818b8a9b1dSJustin T. Gibbs 	char 	    dev_name[DEV_IDLEN];/* Device name for SIM */
6827af2f2c8SWarner Losh 	uint32_t   unit_number;	/* Unit number for SIM */
6837af2f2c8SWarner Losh 	uint32_t   bus_id;		/* Bus ID for SIM */
6847af2f2c8SWarner Losh 	uint32_t   base_transfer_speed;/* Base bus speed in KB/sec */
6853393f8daSKenneth D. Merry 	cam_proto   protocol;
6863393f8daSKenneth D. Merry 	u_int	    protocol_version;
6873393f8daSKenneth D. Merry 	cam_xport   transport;
6883393f8daSKenneth D. Merry 	u_int	    transport_version;
6893393f8daSKenneth D. Merry 	union {
6903393f8daSKenneth D. Merry 		struct ccb_pathinq_settings_spi spi;
691fd13aa47SMatt Jacob 		struct ccb_pathinq_settings_fc fc;
692c4270cb6SMatt Jacob 		struct ccb_pathinq_settings_sas sas;
693f24c011bSWarner Losh 		struct ccb_pathinq_settings_nvme nvme;
694*07c6a62bSJohn Baldwin 		struct ccb_pathinq_settings_nvmf nvmf;
695fd13aa47SMatt Jacob 		char ccb_pathinq_settings_opaque[PATHINQ_SETTINGS_SIZE];
6963393f8daSKenneth D. Merry 	} xport_specific;
69752c9ce25SScott Long 	u_int		maxio;		/* Max supported I/O size, in bytes. */
6987af2f2c8SWarner Losh 	uint16_t	hba_vendor;	/* HBA vendor ID */
6997af2f2c8SWarner Losh 	uint16_t	hba_device;	/* HBA device ID */
7007af2f2c8SWarner Losh 	uint16_t	hba_subvendor;	/* HBA subvendor ID */
7017af2f2c8SWarner Losh 	uint16_t	hba_subdevice;	/* HBA subdevice ID */
7028b8a9b1dSJustin T. Gibbs };
7038b8a9b1dSJustin T. Gibbs 
70487cfaf0eSJustin T. Gibbs /* Path Statistics CCB */
70587cfaf0eSJustin T. Gibbs struct ccb_pathstats {
70687cfaf0eSJustin T. Gibbs 	struct	ccb_hdr	ccb_h;
70787cfaf0eSJustin T. Gibbs 	struct	timeval last_reset;	/* Time of last bus reset/loop init */
70887cfaf0eSJustin T. Gibbs };
70987cfaf0eSJustin T. Gibbs 
71006e79492SKenneth D. Merry typedef enum {
71106e79492SKenneth D. Merry 	SMP_FLAG_NONE		= 0x00,
71206e79492SKenneth D. Merry 	SMP_FLAG_REQ_SG		= 0x01,
71306e79492SKenneth D. Merry 	SMP_FLAG_RSP_SG		= 0x02
71406e79492SKenneth D. Merry } ccb_smp_pass_flags;
71506e79492SKenneth D. Merry 
71606e79492SKenneth D. Merry /*
71706e79492SKenneth D. Merry  * Serial Management Protocol CCB
71806e79492SKenneth D. Merry  * XXX Currently the semantics for this CCB are that it is executed either
71906e79492SKenneth D. Merry  * by the addressed device, or that device's parent (i.e. an expander for
72006e79492SKenneth D. Merry  * any device on an expander) if the addressed device doesn't support SMP.
72106e79492SKenneth D. Merry  * Later, once we have the ability to probe SMP-only devices and put them
72206e79492SKenneth D. Merry  * in CAM's topology, the CCB will only be executed by the addressed device
72306e79492SKenneth D. Merry  * if possible.
72406e79492SKenneth D. Merry  */
72506e79492SKenneth D. Merry struct ccb_smpio {
72606e79492SKenneth D. Merry 	struct ccb_hdr		ccb_h;
72706e79492SKenneth D. Merry 	uint8_t			*smp_request;
72806e79492SKenneth D. Merry 	int			smp_request_len;
72906e79492SKenneth D. Merry 	uint16_t		smp_request_sglist_cnt;
73006e79492SKenneth D. Merry 	uint8_t			*smp_response;
73106e79492SKenneth D. Merry 	int			smp_response_len;
73206e79492SKenneth D. Merry 	uint16_t		smp_response_sglist_cnt;
73306e79492SKenneth D. Merry 	ccb_smp_pass_flags	flags;
73406e79492SKenneth D. Merry };
73506e79492SKenneth D. Merry 
7368b8a9b1dSJustin T. Gibbs typedef union {
7377af2f2c8SWarner Losh 	uint8_t *sense_ptr;		/*
7388b8a9b1dSJustin T. Gibbs 					 * Pointer to storage
7398b8a9b1dSJustin T. Gibbs 					 * for sense information
7408b8a9b1dSJustin T. Gibbs 					 */
7418b8a9b1dSJustin T. Gibbs 	                                /* Storage Area for sense information */
7428b8a9b1dSJustin T. Gibbs 	struct	 scsi_sense_data sense_buf;
7438b8a9b1dSJustin T. Gibbs } sense_t;
7448b8a9b1dSJustin T. Gibbs 
7458b8a9b1dSJustin T. Gibbs typedef union {
7467af2f2c8SWarner Losh 	uint8_t  *cdb_ptr;		/* Pointer to the CDB bytes to send */
7478b8a9b1dSJustin T. Gibbs 					/* Area for the CDB send */
7487af2f2c8SWarner Losh 	uint8_t  cdb_bytes[IOCDBLEN];
7498b8a9b1dSJustin T. Gibbs } cdb_t;
7508b8a9b1dSJustin T. Gibbs 
7518b8a9b1dSJustin T. Gibbs /*
7528b8a9b1dSJustin T. Gibbs  * SCSI I/O Request CCB used for the XPT_SCSI_IO and XPT_CONT_TARGET_IO
7538b8a9b1dSJustin T. Gibbs  * function codes.
7548b8a9b1dSJustin T. Gibbs  */
7558b8a9b1dSJustin T. Gibbs struct ccb_scsiio {
7568b8a9b1dSJustin T. Gibbs 	struct	   ccb_hdr ccb_h;
7578b8a9b1dSJustin T. Gibbs 	union	   ccb *next_ccb;	/* Ptr for next CCB for action */
7587af2f2c8SWarner Losh 	uint8_t   *req_map;		/* Ptr to mapping info */
7597af2f2c8SWarner Losh 	uint8_t   *data_ptr;		/* Ptr to the data buf/SG list */
7607af2f2c8SWarner Losh 	uint32_t  dxfer_len;		/* Data transfer length */
7618b8a9b1dSJustin T. Gibbs 					/* Autosense storage */
7628b8a9b1dSJustin T. Gibbs 	struct     scsi_sense_data sense_data;
7637af2f2c8SWarner Losh 	uint8_t   sense_len;		/* Number of bytes to autosense */
7647af2f2c8SWarner Losh 	uint8_t   cdb_len;		/* Number of bytes for the CDB */
7657af2f2c8SWarner Losh 	uint16_t  sglist_cnt;		/* Number of SG list entries */
7667af2f2c8SWarner Losh 	uint8_t   scsi_status;		/* Returned SCSI status */
7677af2f2c8SWarner Losh 	uint8_t   sense_resid;		/* Autosense resid length: 2's comp */
7687af2f2c8SWarner Losh 	uint32_t  resid;		/* Transfer residual length: 2's comp */
7698b8a9b1dSJustin T. Gibbs 	cdb_t	   cdb_io;		/* Union for CDB bytes/pointer */
7707af2f2c8SWarner Losh 	uint8_t   *msg_ptr;		/* Pointer to the message buffer */
7717af2f2c8SWarner Losh 	uint16_t  msg_len;		/* Number of bytes for the Message */
7727af2f2c8SWarner Losh 	uint8_t   tag_action;		/* What to do for tag queueing */
773bb1f2fe4SJustin T. Gibbs 	/*
774bb1f2fe4SJustin T. Gibbs 	 * The tag action should be either the define below (to send a
775bb1f2fe4SJustin T. Gibbs 	 * non-tagged transaction) or one of the defined scsi tag messages
776bb1f2fe4SJustin T. Gibbs 	 * from scsi_message.h.
777bb1f2fe4SJustin T. Gibbs 	 */
778bb1f2fe4SJustin T. Gibbs #define		CAM_TAG_ACTION_NONE	0x00
77988364968SAlexander Motin 	uint8_t	   priority;		/* Command priority for SIMPLE tag */
780bf8bb7acSJustin T. Gibbs 	u_int	   tag_id;		/* tag id from initator (target mode) */
781bf8bb7acSJustin T. Gibbs 	u_int	   init_id;		/* initiator id of who selected */
7828532d381SConrad Meyer #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
7838532d381SConrad Meyer 	struct bio *bio;		/* Associated bio */
7848532d381SConrad Meyer #endif
7858b8a9b1dSJustin T. Gibbs };
7868b8a9b1dSJustin T. Gibbs 
7874aa947cbSWarner Losh static __inline uint8_t *
7884aa947cbSWarner Losh scsiio_cdb_ptr(struct ccb_scsiio *ccb)
7894aa947cbSWarner Losh {
7904aa947cbSWarner Losh 	return ((ccb->ccb_h.flags & CAM_CDB_POINTER) ?
7914aa947cbSWarner Losh 	    ccb->cdb_io.cdb_ptr : ccb->cdb_io.cdb_bytes);
7924aa947cbSWarner Losh }
7934aa947cbSWarner Losh 
79452c9ce25SScott Long /*
79552c9ce25SScott Long  * ATA I/O Request CCB used for the XPT_ATA_IO function code.
79652c9ce25SScott Long  */
79752c9ce25SScott Long struct ccb_ataio {
79852c9ce25SScott Long 	struct	   ccb_hdr ccb_h;
79952c9ce25SScott Long 	union	   ccb *next_ccb;	/* Ptr for next CCB for action */
80052c9ce25SScott Long 	struct ata_cmd	cmd;		/* ATA command register set */
80152c9ce25SScott Long 	struct ata_res	res;		/* ATA result register set */
8027af2f2c8SWarner Losh 	uint8_t   *data_ptr;		/* Ptr to the data buf/SG list */
8037af2f2c8SWarner Losh 	uint32_t  dxfer_len;		/* Data transfer length */
8047af2f2c8SWarner Losh 	uint32_t  resid;		/* Transfer residual length: 2's comp */
8057af2f2c8SWarner Losh 	uint8_t   ata_flags;		/* Flags for the rest of the buffer */
806916d57dfSWarner Losh #define ATA_FLAG_AUX 0x1
80706c888ecSAlexander Motin #define ATA_FLAG_ICC 0x2
80806c888ecSAlexander Motin 	uint8_t    icc;			/* Isochronous Command Completion */
809916d57dfSWarner Losh 	uint32_t   aux;
810916d57dfSWarner Losh 	uint32_t   unused;
81152c9ce25SScott Long };
81252c9ce25SScott Long 
813a94a63f0SWarner Losh /*
814a94a63f0SWarner Losh  * MMC I/O Request CCB used for the XPT_MMC_IO function code.
815a94a63f0SWarner Losh  */
816a94a63f0SWarner Losh struct ccb_mmcio {
817a94a63f0SWarner Losh 	struct	   ccb_hdr ccb_h;
818a94a63f0SWarner Losh 	union	   ccb *next_ccb;	/* Ptr for next CCB for action */
819a94a63f0SWarner Losh 	struct mmc_command cmd;
820a94a63f0SWarner Losh         struct mmc_command stop;
821a94a63f0SWarner Losh };
822a94a63f0SWarner Losh 
8238b8a9b1dSJustin T. Gibbs struct ccb_accept_tio {
8248b8a9b1dSJustin T. Gibbs 	struct	   ccb_hdr ccb_h;
8258b8a9b1dSJustin T. Gibbs 	cdb_t	   cdb_io;		/* Union for CDB bytes/pointer */
8267af2f2c8SWarner Losh 	uint8_t   cdb_len;		/* Number of bytes for the CDB */
8277af2f2c8SWarner Losh 	uint8_t   tag_action;		/* What to do for tag queueing */
8287af2f2c8SWarner Losh 	uint8_t   sense_len;		/* Number of bytes of Sense Data */
82988364968SAlexander Motin 	uint8_t	   priority;		/* Command priority for SIMPLE tag */
8302759b3c7SMatt Jacob 	u_int      tag_id;		/* tag id from initator (target mode) */
8312759b3c7SMatt Jacob 	u_int      init_id;		/* initiator id of who selected */
832826eb7c8SMatt Jacob 	struct     scsi_sense_data sense_data;
8338b8a9b1dSJustin T. Gibbs };
8348b8a9b1dSJustin T. Gibbs 
8354902e14dSAlexander Motin static __inline uint8_t *
8364902e14dSAlexander Motin atio_cdb_ptr(struct ccb_accept_tio *ccb)
8374902e14dSAlexander Motin {
8384902e14dSAlexander Motin 	return ((ccb->ccb_h.flags & CAM_CDB_POINTER) ?
8394902e14dSAlexander Motin 	    ccb->cdb_io.cdb_ptr : ccb->cdb_io.cdb_bytes);
8404902e14dSAlexander Motin }
8414902e14dSAlexander Motin 
8428b8a9b1dSJustin T. Gibbs /* Release SIM Queue */
8438b8a9b1dSJustin T. Gibbs struct ccb_relsim {
8448b8a9b1dSJustin T. Gibbs 	struct ccb_hdr ccb_h;
8457af2f2c8SWarner Losh 	uint32_t      release_flags;
8468b8a9b1dSJustin T. Gibbs #define RELSIM_ADJUST_OPENINGS		0x01
8478b8a9b1dSJustin T. Gibbs #define RELSIM_RELEASE_AFTER_TIMEOUT	0x02
8488b8a9b1dSJustin T. Gibbs #define RELSIM_RELEASE_AFTER_CMDCMPLT	0x04
8498b8a9b1dSJustin T. Gibbs #define RELSIM_RELEASE_AFTER_QEMPTY	0x08
8507af2f2c8SWarner Losh 	uint32_t      openings;
8517af2f2c8SWarner Losh 	uint32_t      release_timeout;	/* Abstract argument. */
8527af2f2c8SWarner Losh 	uint32_t      qfrozen_cnt;
8538b8a9b1dSJustin T. Gibbs };
8548b8a9b1dSJustin T. Gibbs 
8558b8a9b1dSJustin T. Gibbs /*
856df424515SWarner Losh  * NVMe I/O Request CCB used for the XPT_NVME_IO and XPT_NVME_ADMIN function codes.
857baabaca3SWarner Losh  */
858baabaca3SWarner Losh struct ccb_nvmeio {
859baabaca3SWarner Losh 	struct	   ccb_hdr ccb_h;
860baabaca3SWarner Losh 	union	   ccb *next_ccb;	/* Ptr for next CCB for action */
861baabaca3SWarner Losh 	struct nvme_command cmd;	/* NVME command, per NVME standard */
862baabaca3SWarner Losh 	struct nvme_completion cpl;	/* NVME completion, per NVME standard */
863baabaca3SWarner Losh 	uint8_t   *data_ptr;		/* Ptr to the data buf/SG list */
864baabaca3SWarner Losh 	uint32_t  dxfer_len;		/* Data transfer length */
86551977281SWarner Losh 	uint16_t  sglist_cnt;		/* Number of SG list entries */
86651977281SWarner Losh 	uint16_t  unused;		/* padding for removed uint32_t */
867baabaca3SWarner Losh };
868baabaca3SWarner Losh 
869baabaca3SWarner Losh /*
8708b8a9b1dSJustin T. Gibbs  * Definitions for the asynchronous callback CCB fields.
8718b8a9b1dSJustin T. Gibbs  */
8728b8a9b1dSJustin T. Gibbs typedef enum {
8733631c638SAlexander Motin 	AC_UNIT_ATTENTION	= 0x4000,/* Device reported UNIT ATTENTION */
8743501942bSJustin T. Gibbs 	AC_ADVINFO_CHANGED	= 0x2000,/* Advance info might have changes */
8752df76c16SMatt Jacob 	AC_CONTRACT		= 0x1000,/* A contractual callback */
8768b8a9b1dSJustin T. Gibbs 	AC_GETDEV_CHANGED	= 0x800,/* Getdev info might have changed */
8778b8a9b1dSJustin T. Gibbs 	AC_INQ_CHANGED		= 0x400,/* Inquiry info might have changed */
8788b8a9b1dSJustin T. Gibbs 	AC_TRANSFER_NEG		= 0x200,/* New transfer settings in effect */
8798b8a9b1dSJustin T. Gibbs 	AC_LOST_DEVICE		= 0x100,/* A device went away */
8808b8a9b1dSJustin T. Gibbs 	AC_FOUND_DEVICE		= 0x080,/* A new device was found */
8818b8a9b1dSJustin T. Gibbs 	AC_PATH_DEREGISTERED	= 0x040,/* A path has de-registered */
8828b8a9b1dSJustin T. Gibbs 	AC_PATH_REGISTERED	= 0x020,/* A new path has been registered */
8838b8a9b1dSJustin T. Gibbs 	AC_SENT_BDR		= 0x010,/* A BDR message was sent to target */
8848b8a9b1dSJustin T. Gibbs 	AC_SCSI_AEN		= 0x008,/* A SCSI AEN has been received */
8858b8a9b1dSJustin T. Gibbs 	AC_UNSOL_RESEL		= 0x002,/* Unsolicited reselection occurred */
8868b8a9b1dSJustin T. Gibbs 	AC_BUS_RESET		= 0x001	/* A SCSI bus reset occurred */
8878b8a9b1dSJustin T. Gibbs } ac_code;
8888b8a9b1dSJustin T. Gibbs 
8897af2f2c8SWarner Losh typedef void ac_callback_t (void *softc, uint32_t code,
8908b8a9b1dSJustin T. Gibbs 			    struct cam_path *path, void *args);
8918b8a9b1dSJustin T. Gibbs 
8922df76c16SMatt Jacob /*
8932df76c16SMatt Jacob  * Generic Asynchronous callbacks.
8942df76c16SMatt Jacob  *
8952df76c16SMatt Jacob  * Generic arguments passed bac which are then interpreted between a per-system
8962df76c16SMatt Jacob  * contract number.
8972df76c16SMatt Jacob  */
8987af2f2c8SWarner Losh #define	AC_CONTRACT_DATA_MAX (128 - sizeof (uint64_t))
8992df76c16SMatt Jacob struct ac_contract {
9007af2f2c8SWarner Losh 	uint64_t	contract_number;
9017af2f2c8SWarner Losh 	uint8_t	contract_data[AC_CONTRACT_DATA_MAX];
9022df76c16SMatt Jacob };
9032df76c16SMatt Jacob 
9042df76c16SMatt Jacob #define	AC_CONTRACT_DEV_CHG	1
9052df76c16SMatt Jacob struct ac_device_changed {
9067af2f2c8SWarner Losh 	uint64_t	wwpn;
9077af2f2c8SWarner Losh 	uint32_t	port;
9082df76c16SMatt Jacob 	target_id_t	target;
9097af2f2c8SWarner Losh 	uint8_t	arrived;
9102df76c16SMatt Jacob };
9112df76c16SMatt Jacob 
9128b8a9b1dSJustin T. Gibbs /* Set Asynchronous Callback CCB */
9138b8a9b1dSJustin T. Gibbs struct ccb_setasync {
9148b8a9b1dSJustin T. Gibbs 	struct ccb_hdr	 ccb_h;
9157af2f2c8SWarner Losh 	uint32_t	 event_enable;	/* Async Event enables */
9168b8a9b1dSJustin T. Gibbs 	ac_callback_t	*callback;
9178b8a9b1dSJustin T. Gibbs 	void		*callback_arg;
9188b8a9b1dSJustin T. Gibbs };
9198b8a9b1dSJustin T. Gibbs 
9208b8a9b1dSJustin T. Gibbs /* Set Device Type CCB */
9218b8a9b1dSJustin T. Gibbs struct ccb_setdev {
9228b8a9b1dSJustin T. Gibbs 	struct	   ccb_hdr ccb_h;
9237af2f2c8SWarner Losh 	uint8_t   dev_type;	/* Value for dev type field in EDT */
9248b8a9b1dSJustin T. Gibbs };
9258b8a9b1dSJustin T. Gibbs 
9268b8a9b1dSJustin T. Gibbs /* SCSI Control Functions */
9278b8a9b1dSJustin T. Gibbs 
9288b8a9b1dSJustin T. Gibbs /* Abort XPT request CCB */
9298b8a9b1dSJustin T. Gibbs struct ccb_abort {
9308b8a9b1dSJustin T. Gibbs 	struct 	ccb_hdr ccb_h;
9318b8a9b1dSJustin T. Gibbs 	union	ccb *abort_ccb;	/* Pointer to CCB to abort */
9328b8a9b1dSJustin T. Gibbs };
9338b8a9b1dSJustin T. Gibbs 
9348b8a9b1dSJustin T. Gibbs /* Reset SCSI Bus CCB */
9358b8a9b1dSJustin T. Gibbs struct ccb_resetbus {
9368b8a9b1dSJustin T. Gibbs 	struct	ccb_hdr ccb_h;
9378b8a9b1dSJustin T. Gibbs };
9388b8a9b1dSJustin T. Gibbs 
9398b8a9b1dSJustin T. Gibbs /* Reset SCSI Device CCB */
9408b8a9b1dSJustin T. Gibbs struct ccb_resetdev {
9418b8a9b1dSJustin T. Gibbs 	struct	ccb_hdr ccb_h;
9428b8a9b1dSJustin T. Gibbs };
9438b8a9b1dSJustin T. Gibbs 
9448b8a9b1dSJustin T. Gibbs /* Terminate I/O Process Request CCB */
9458b8a9b1dSJustin T. Gibbs struct ccb_termio {
9468b8a9b1dSJustin T. Gibbs 	struct	ccb_hdr ccb_h;
9478b8a9b1dSJustin T. Gibbs 	union	ccb *termio_ccb;	/* Pointer to CCB to terminate */
9488b8a9b1dSJustin T. Gibbs };
9498b8a9b1dSJustin T. Gibbs 
9503393f8daSKenneth D. Merry typedef enum {
9513393f8daSKenneth D. Merry 	CTS_TYPE_CURRENT_SETTINGS,
9523393f8daSKenneth D. Merry 	CTS_TYPE_USER_SETTINGS
9533393f8daSKenneth D. Merry } cts_type;
9543393f8daSKenneth D. Merry 
9553393f8daSKenneth D. Merry struct ccb_trans_settings_scsi
9563393f8daSKenneth D. Merry {
9573393f8daSKenneth D. Merry 	u_int	valid;	/* Which fields to honor */
9583393f8daSKenneth D. Merry #define	CTS_SCSI_VALID_TQ		0x01
9593393f8daSKenneth D. Merry 	u_int	flags;
9603393f8daSKenneth D. Merry #define	CTS_SCSI_FLAGS_TAG_ENB		0x01
9613393f8daSKenneth D. Merry };
9623393f8daSKenneth D. Merry 
963b9c473b2SAlexander Motin struct ccb_trans_settings_ata
964b9c473b2SAlexander Motin {
965b9c473b2SAlexander Motin 	u_int	valid;	/* Which fields to honor */
966b9c473b2SAlexander Motin #define	CTS_ATA_VALID_TQ		0x01
967b9c473b2SAlexander Motin 	u_int	flags;
968b9c473b2SAlexander Motin #define	CTS_ATA_FLAGS_TAG_ENB		0x01
969b9c473b2SAlexander Motin };
970b9c473b2SAlexander Motin 
9713393f8daSKenneth D. Merry struct ccb_trans_settings_spi
9723393f8daSKenneth D. Merry {
9733393f8daSKenneth D. Merry 	u_int	  valid;	/* Which fields to honor */
9743393f8daSKenneth D. Merry #define	CTS_SPI_VALID_SYNC_RATE		0x01
9753393f8daSKenneth D. Merry #define	CTS_SPI_VALID_SYNC_OFFSET	0x02
9763393f8daSKenneth D. Merry #define	CTS_SPI_VALID_BUS_WIDTH		0x04
9773393f8daSKenneth D. Merry #define	CTS_SPI_VALID_DISC		0x08
9783393f8daSKenneth D. Merry #define CTS_SPI_VALID_PPR_OPTIONS	0x10
9793393f8daSKenneth D. Merry 	u_int	flags;
9803393f8daSKenneth D. Merry #define	CTS_SPI_FLAGS_DISC_ENB		0x01
9813393f8daSKenneth D. Merry 	u_int	sync_period;
9823393f8daSKenneth D. Merry 	u_int	sync_offset;
9833393f8daSKenneth D. Merry 	u_int	bus_width;
9843393f8daSKenneth D. Merry 	u_int	ppr_options;
9853393f8daSKenneth D. Merry };
9863393f8daSKenneth D. Merry 
987c1c84cd9SMatt Jacob struct ccb_trans_settings_fc {
988c1c84cd9SMatt Jacob 	u_int     	valid;		/* Which fields to honor */
989c1c84cd9SMatt Jacob #define	CTS_FC_VALID_WWNN		0x8000
990c1c84cd9SMatt Jacob #define	CTS_FC_VALID_WWPN		0x4000
991c1c84cd9SMatt Jacob #define	CTS_FC_VALID_PORT		0x2000
992c1c84cd9SMatt Jacob #define	CTS_FC_VALID_SPEED		0x1000
9937af2f2c8SWarner Losh 	uint64_t	wwnn;		/* world wide node name */
9947af2f2c8SWarner Losh 	uint64_t 	wwpn;		/* world wide port name */
9957af2f2c8SWarner Losh 	uint32_t 	port;		/* 24 bit port id, if known */
9967af2f2c8SWarner Losh 	uint32_t 	bitrate;	/* Mbps */
997c1c84cd9SMatt Jacob };
998c1c84cd9SMatt Jacob 
999c4270cb6SMatt Jacob struct ccb_trans_settings_sas {
1000c4270cb6SMatt Jacob 	u_int     	valid;		/* Which fields to honor */
1001c4270cb6SMatt Jacob #define	CTS_SAS_VALID_SPEED		0x1000
10027af2f2c8SWarner Losh 	uint32_t 	bitrate;	/* Mbps */
1003c4270cb6SMatt Jacob };
1004c4270cb6SMatt Jacob 
1005b9c473b2SAlexander Motin struct ccb_trans_settings_pata {
10061e637ba6SAlexander Motin 	u_int     	valid;		/* Which fields to honor */
10071e637ba6SAlexander Motin #define	CTS_ATA_VALID_MODE		0x01
1008c8039fc6SAlexander Motin #define	CTS_ATA_VALID_BYTECOUNT		0x02
10094cca1530SAlexander Motin #define	CTS_ATA_VALID_ATAPI		0x20
10102e1eb332SMarius Strobl #define	CTS_ATA_VALID_CAPS		0x40
1011c8039fc6SAlexander Motin 	int		mode;		/* Mode */
10121e637ba6SAlexander Motin 	u_int 		bytecount;	/* Length of PIO transaction */
10134cca1530SAlexander Motin 	u_int 		atapi;		/* Length of ATAPI CDB */
10142e1eb332SMarius Strobl 	u_int 		caps;		/* Device and host SATA caps. */
10152e1eb332SMarius Strobl #define	CTS_ATA_CAPS_H			0x0000ffff
10162e1eb332SMarius Strobl #define	CTS_ATA_CAPS_H_DMA48		0x00000001 /* 48-bit DMA */
10172e1eb332SMarius Strobl #define	CTS_ATA_CAPS_D			0xffff0000
10181e637ba6SAlexander Motin };
10191e637ba6SAlexander Motin 
102052c9ce25SScott Long struct ccb_trans_settings_sata {
102152c9ce25SScott Long 	u_int     	valid;		/* Which fields to honor */
1022c8039fc6SAlexander Motin #define	CTS_SATA_VALID_MODE		0x01
1023c8039fc6SAlexander Motin #define	CTS_SATA_VALID_BYTECOUNT	0x02
1024c8039fc6SAlexander Motin #define	CTS_SATA_VALID_REVISION		0x04
1025c8039fc6SAlexander Motin #define	CTS_SATA_VALID_PM		0x08
1026c8039fc6SAlexander Motin #define	CTS_SATA_VALID_TAGS		0x10
10274cca1530SAlexander Motin #define	CTS_SATA_VALID_ATAPI		0x20
1028da6808c1SAlexander Motin #define	CTS_SATA_VALID_CAPS		0x40
1029c8039fc6SAlexander Motin 	int		mode;		/* Legacy PATA mode */
10301e637ba6SAlexander Motin 	u_int 		bytecount;	/* Length of PIO transaction */
1031b447e682SAlexander Motin 	int		revision;	/* SATA revision */
1032c8039fc6SAlexander Motin 	u_int 		pm_present;	/* PM is present (XPT->SIM) */
1033c8039fc6SAlexander Motin 	u_int 		tags;		/* Number of allowed tags */
10344cca1530SAlexander Motin 	u_int 		atapi;		/* Length of ATAPI CDB */
1035da6808c1SAlexander Motin 	u_int 		caps;		/* Device and host SATA caps. */
1036da6808c1SAlexander Motin #define	CTS_SATA_CAPS_H			0x0000ffff
1037da6808c1SAlexander Motin #define	CTS_SATA_CAPS_H_PMREQ		0x00000001
1038da6808c1SAlexander Motin #define	CTS_SATA_CAPS_H_APST		0x00000002
1039da6808c1SAlexander Motin #define	CTS_SATA_CAPS_H_DMAAA		0x00000010 /* Auto-activation */
10408d169381SAlexander Motin #define	CTS_SATA_CAPS_H_AN		0x00000020 /* Async. notification */
1041da6808c1SAlexander Motin #define	CTS_SATA_CAPS_D			0xffff0000
1042da6808c1SAlexander Motin #define	CTS_SATA_CAPS_D_PMREQ		0x00010000
1043da6808c1SAlexander Motin #define	CTS_SATA_CAPS_D_APST		0x00020000
104452c9ce25SScott Long };
1045c4270cb6SMatt Jacob 
1046f24c011bSWarner Losh struct ccb_trans_settings_nvme
1047f24c011bSWarner Losh {
1048f24c011bSWarner Losh 	u_int     	valid;		/* Which fields to honor */
1049f24c011bSWarner Losh #define CTS_NVME_VALID_SPEC	0x01
1050f24c011bSWarner Losh #define CTS_NVME_VALID_CAPS	0x02
10514e3b2744SWarner Losh #define CTS_NVME_VALID_LINK	0x04
10524e3b2744SWarner Losh 	uint32_t	spec;		/* NVMe spec implemented -- same as vs register */
10534e3b2744SWarner Losh 	uint32_t	max_xfer;	/* Max transfer size (0 -> unlimited */
10544e3b2744SWarner Losh 	uint32_t	caps;
10554e3b2744SWarner Losh 	uint8_t		lanes;		/* Number of PCIe lanes */
10564e3b2744SWarner Losh 	uint8_t		speed;		/* PCIe generation for each lane */
10574e3b2744SWarner Losh 	uint8_t		max_lanes;	/* Number of PCIe lanes */
10584e3b2744SWarner Losh 	uint8_t		max_speed;	/* PCIe generation for each lane */
1059f24c011bSWarner Losh };
1060f24c011bSWarner Losh 
1061*07c6a62bSJohn Baldwin struct ccb_trans_settings_nvmf
1062*07c6a62bSJohn Baldwin {
1063*07c6a62bSJohn Baldwin 	u_int     	valid;		/* Which fields to honor */
1064*07c6a62bSJohn Baldwin #define CTS_NVMF_VALID_TRTYPE	0x01
1065*07c6a62bSJohn Baldwin 	uint8_t		trtype;
1066*07c6a62bSJohn Baldwin };
1067*07c6a62bSJohn Baldwin 
1068a94a63f0SWarner Losh #include <cam/mmc/mmc_bus.h>
1069a94a63f0SWarner Losh struct ccb_trans_settings_mmc {
1070a94a63f0SWarner Losh 	struct mmc_ios ios;
1071a94a63f0SWarner Losh #define MMC_CLK		(1 << 1)
1072a94a63f0SWarner Losh #define MMC_VDD		(1 << 2)
1073a94a63f0SWarner Losh #define MMC_CS		(1 << 3)
1074a94a63f0SWarner Losh #define MMC_BW		(1 << 4)
1075a94a63f0SWarner Losh #define MMC_PM		(1 << 5)
1076a94a63f0SWarner Losh #define MMC_BT		(1 << 6)
1077a94a63f0SWarner Losh #define MMC_BM		(1 << 7)
10782657d8e3SEmmanuel Vadot #define MMC_VCCQ        (1 << 8)
1079a94a63f0SWarner Losh 	uint32_t ios_valid;
1080a94a63f0SWarner Losh /* The folowing is used only for GET_TRAN_SETTINGS */
1081a94a63f0SWarner Losh 	uint32_t	host_ocr;
1082a94a63f0SWarner Losh 	int host_f_min;
1083a94a63f0SWarner Losh 	int host_f_max;
10842657d8e3SEmmanuel Vadot /* Copied from sys/dev/mmc/bridge.h */
1085a94a63f0SWarner Losh #define	MMC_CAP_4_BIT_DATA	(1 <<  0) /* Can do 4-bit data transfers */
1086a94a63f0SWarner Losh #define	MMC_CAP_8_BIT_DATA	(1 <<  1) /* Can do 8-bit data transfers */
1087a94a63f0SWarner Losh #define	MMC_CAP_HSPEED		(1 <<  2) /* Can do High Speed transfers */
10882657d8e3SEmmanuel Vadot #define	MMC_CAP_BOOT_NOACC	(1 <<  4) /* Cannot access boot partitions */
10892657d8e3SEmmanuel Vadot #define	MMC_CAP_WAIT_WHILE_BUSY	(1 <<  5) /* Host waits for busy responses */
10902657d8e3SEmmanuel Vadot #define	MMC_CAP_UHS_SDR12	(1 <<  6) /* Can do UHS SDR12 */
10912657d8e3SEmmanuel Vadot #define	MMC_CAP_UHS_SDR25	(1 <<  7) /* Can do UHS SDR25 */
10922657d8e3SEmmanuel Vadot #define	MMC_CAP_UHS_SDR50	(1 <<  8) /* Can do UHS SDR50 */
10932657d8e3SEmmanuel Vadot #define	MMC_CAP_UHS_SDR104	(1 <<  9) /* Can do UHS SDR104 */
10942657d8e3SEmmanuel Vadot #define	MMC_CAP_UHS_DDR50	(1 << 10) /* Can do UHS DDR50 */
10952657d8e3SEmmanuel Vadot #define	MMC_CAP_MMC_DDR52_120	(1 << 11) /* Can do eMMC DDR52 at 1.2 V */
10962657d8e3SEmmanuel Vadot #define	MMC_CAP_MMC_DDR52_180	(1 << 12) /* Can do eMMC DDR52 at 1.8 V */
10972657d8e3SEmmanuel Vadot #define	MMC_CAP_MMC_DDR52	(MMC_CAP_MMC_DDR52_120 | MMC_CAP_MMC_DDR52_180)
10982657d8e3SEmmanuel Vadot #define	MMC_CAP_MMC_HS200_120	(1 << 13) /* Can do eMMC HS200 at 1.2 V */
10992657d8e3SEmmanuel Vadot #define	MMC_CAP_MMC_HS200_180	(1 << 14) /* Can do eMMC HS200 at 1.8 V */
11002657d8e3SEmmanuel Vadot #define	MMC_CAP_MMC_HS200	(MMC_CAP_MMC_HS200_120| MMC_CAP_MMC_HS200_180)
11012657d8e3SEmmanuel Vadot #define	MMC_CAP_MMC_HS400_120	(1 << 15) /* Can do eMMC HS400 at 1.2 V */
11022657d8e3SEmmanuel Vadot #define	MMC_CAP_MMC_HS400_180	(1 << 16) /* Can do eMMC HS400 at 1.8 V */
11032657d8e3SEmmanuel Vadot #define	MMC_CAP_MMC_HS400	(MMC_CAP_MMC_HS400_120 | MMC_CAP_MMC_HS400_180)
11042657d8e3SEmmanuel Vadot #define	MMC_CAP_MMC_HSX00_120	(MMC_CAP_MMC_HS200_120 | MMC_CAP_MMC_HS400_120)
11052657d8e3SEmmanuel Vadot #define	MMC_CAP_MMC_ENH_STROBE	(1 << 17) /* Can do eMMC Enhanced Strobe */
11062657d8e3SEmmanuel Vadot #define	MMC_CAP_SIGNALING_120	(1 << 18) /* Can do signaling at 1.2 V */
11072657d8e3SEmmanuel Vadot #define	MMC_CAP_SIGNALING_180	(1 << 19) /* Can do signaling at 1.8 V */
11082657d8e3SEmmanuel Vadot #define	MMC_CAP_SIGNALING_330	(1 << 20) /* Can do signaling at 3.3 V */
11092657d8e3SEmmanuel Vadot #define	MMC_CAP_DRIVER_TYPE_A	(1 << 21) /* Can do Driver Type A */
11102657d8e3SEmmanuel Vadot #define	MMC_CAP_DRIVER_TYPE_C	(1 << 22) /* Can do Driver Type C */
11112657d8e3SEmmanuel Vadot #define	MMC_CAP_DRIVER_TYPE_D	(1 << 23) /* Can do Driver Type D */
11122657d8e3SEmmanuel Vadot 
1113a94a63f0SWarner Losh 	uint32_t host_caps;
11145d20e651SIlya Bakulin 	uint32_t host_max_data;
1115a94a63f0SWarner Losh };
1116a94a63f0SWarner Losh 
11173393f8daSKenneth D. Merry /* Get/Set transfer rate/width/disconnection/tag queueing settings */
11183393f8daSKenneth D. Merry struct ccb_trans_settings {
11193393f8daSKenneth D. Merry 	struct	  ccb_hdr ccb_h;
11203393f8daSKenneth D. Merry 	cts_type  type;		/* Current or User settings */
11213393f8daSKenneth D. Merry 	cam_proto protocol;
11223393f8daSKenneth D. Merry 	u_int	  protocol_version;
11233393f8daSKenneth D. Merry 	cam_xport transport;
11243393f8daSKenneth D. Merry 	u_int	  transport_version;
11253393f8daSKenneth D. Merry 	union {
11263393f8daSKenneth D. Merry 		u_int  valid;	/* Which fields to honor */
1127b9c473b2SAlexander Motin 		struct ccb_trans_settings_ata ata;
11283393f8daSKenneth D. Merry 		struct ccb_trans_settings_scsi scsi;
1129f24c011bSWarner Losh 		struct ccb_trans_settings_nvme nvme;
1130a94a63f0SWarner Losh 		struct ccb_trans_settings_mmc mmc;
11313393f8daSKenneth D. Merry 	} proto_specific;
11323393f8daSKenneth D. Merry 	union {
11333393f8daSKenneth D. Merry 		u_int  valid;	/* Which fields to honor */
11343393f8daSKenneth D. Merry 		struct ccb_trans_settings_spi spi;
1135c1c84cd9SMatt Jacob 		struct ccb_trans_settings_fc fc;
1136c4270cb6SMatt Jacob 		struct ccb_trans_settings_sas sas;
1137b9c473b2SAlexander Motin 		struct ccb_trans_settings_pata ata;
113852c9ce25SScott Long 		struct ccb_trans_settings_sata sata;
1139f24c011bSWarner Losh 		struct ccb_trans_settings_nvme nvme;
1140*07c6a62bSJohn Baldwin 		struct ccb_trans_settings_nvmf nvmf;
11413393f8daSKenneth D. Merry 	} xport_specific;
11423393f8daSKenneth D. Merry };
11433393f8daSKenneth D. Merry 
11448b8a9b1dSJustin T. Gibbs /*
11458b8a9b1dSJustin T. Gibbs  * Calculate the geometry parameters for a device
11468b8a9b1dSJustin T. Gibbs  * give the block size and volume size in blocks.
11478b8a9b1dSJustin T. Gibbs  */
11488b8a9b1dSJustin T. Gibbs struct ccb_calc_geometry {
11498b8a9b1dSJustin T. Gibbs 	struct	  ccb_hdr ccb_h;
11507af2f2c8SWarner Losh 	uint32_t block_size;
11517af2f2c8SWarner Losh 	uint64_t volume_size;
11527af2f2c8SWarner Losh 	uint32_t cylinders;
11537af2f2c8SWarner Losh 	uint8_t  heads;
11547af2f2c8SWarner Losh 	uint8_t  secs_per_track;
11558b8a9b1dSJustin T. Gibbs };
11568b8a9b1dSJustin T. Gibbs 
11578b8a9b1dSJustin T. Gibbs /*
11582df76c16SMatt Jacob  * Set or get SIM (and transport) specific knobs
11592df76c16SMatt Jacob  */
11602df76c16SMatt Jacob 
11612df76c16SMatt Jacob #define	KNOB_VALID_ADDRESS	0x1
11622df76c16SMatt Jacob #define	KNOB_VALID_ROLE		0x2
11632df76c16SMatt Jacob 
11642df76c16SMatt Jacob #define	KNOB_ROLE_NONE		0x0
11652df76c16SMatt Jacob #define	KNOB_ROLE_INITIATOR	0x1
11662df76c16SMatt Jacob #define	KNOB_ROLE_TARGET	0x2
11672df76c16SMatt Jacob #define	KNOB_ROLE_BOTH		0x3
11682df76c16SMatt Jacob 
11692df76c16SMatt Jacob struct ccb_sim_knob_settings_spi {
11702df76c16SMatt Jacob 	u_int		valid;
11712df76c16SMatt Jacob 	u_int		initiator_id;
11722df76c16SMatt Jacob 	u_int		role;
11732df76c16SMatt Jacob };
11742df76c16SMatt Jacob 
11752df76c16SMatt Jacob struct ccb_sim_knob_settings_fc {
11762df76c16SMatt Jacob 	u_int		valid;
11777af2f2c8SWarner Losh 	uint64_t	wwnn;		/* world wide node name */
11787af2f2c8SWarner Losh 	uint64_t 	wwpn;		/* world wide port name */
11792df76c16SMatt Jacob 	u_int		role;
11802df76c16SMatt Jacob };
11812df76c16SMatt Jacob 
11822df76c16SMatt Jacob struct ccb_sim_knob_settings_sas {
11832df76c16SMatt Jacob 	u_int		valid;
11847af2f2c8SWarner Losh 	uint64_t	wwnn;		/* world wide node name */
11852df76c16SMatt Jacob 	u_int		role;
11862df76c16SMatt Jacob };
11872df76c16SMatt Jacob #define	KNOB_SETTINGS_SIZE	128
11882df76c16SMatt Jacob 
11892df76c16SMatt Jacob struct ccb_sim_knob {
11902df76c16SMatt Jacob 	struct	  ccb_hdr ccb_h;
11912df76c16SMatt Jacob 	union {
11922df76c16SMatt Jacob 		u_int  valid;	/* Which fields to honor */
11932df76c16SMatt Jacob 		struct ccb_sim_knob_settings_spi spi;
11942df76c16SMatt Jacob 		struct ccb_sim_knob_settings_fc fc;
11952df76c16SMatt Jacob 		struct ccb_sim_knob_settings_sas sas;
11962df76c16SMatt Jacob 		char pad[KNOB_SETTINGS_SIZE];
11972df76c16SMatt Jacob 	} xport_specific;
11982df76c16SMatt Jacob };
11992df76c16SMatt Jacob 
12002df76c16SMatt Jacob /*
12018b8a9b1dSJustin T. Gibbs  * Rescan the given bus, or bus/target/lun
12028b8a9b1dSJustin T. Gibbs  */
12038b8a9b1dSJustin T. Gibbs struct ccb_rescan {
12048b8a9b1dSJustin T. Gibbs 	struct	ccb_hdr ccb_h;
12058b8a9b1dSJustin T. Gibbs 	cam_flags	flags;
12068b8a9b1dSJustin T. Gibbs };
12078b8a9b1dSJustin T. Gibbs 
12088b8a9b1dSJustin T. Gibbs /*
12098b8a9b1dSJustin T. Gibbs  * Turn on debugging for the given bus, bus/target, or bus/target/lun.
12108b8a9b1dSJustin T. Gibbs  */
12118b8a9b1dSJustin T. Gibbs struct ccb_debug {
12128b8a9b1dSJustin T. Gibbs 	struct	ccb_hdr ccb_h;
12138b8a9b1dSJustin T. Gibbs 	cam_debug_flags flags;
12148b8a9b1dSJustin T. Gibbs };
12158b8a9b1dSJustin T. Gibbs 
12168b8a9b1dSJustin T. Gibbs /* Target mode structures. */
12178b8a9b1dSJustin T. Gibbs 
12188b8a9b1dSJustin T. Gibbs struct ccb_en_lun {
12198b8a9b1dSJustin T. Gibbs 	struct	  ccb_hdr ccb_h;
12207af2f2c8SWarner Losh 	uint16_t grp6_len;		/* Group 6 VU CDB length */
12217af2f2c8SWarner Losh 	uint16_t grp7_len;		/* Group 7 VU CDB length */
12227af2f2c8SWarner Losh 	uint8_t  enable;
12238b8a9b1dSJustin T. Gibbs };
12248b8a9b1dSJustin T. Gibbs 
12252df76c16SMatt Jacob /* old, barely used immediate notify, binary compatibility */
12268b8a9b1dSJustin T. Gibbs struct ccb_immed_notify {
12278b8a9b1dSJustin T. Gibbs 	struct	  ccb_hdr ccb_h;
12288b8a9b1dSJustin T. Gibbs 	struct    scsi_sense_data sense_data;
12297af2f2c8SWarner Losh 	uint8_t  sense_len;		/* Number of bytes in sense buffer */
12307af2f2c8SWarner Losh 	uint8_t  initiator_id;		/* Id of initiator that selected */
12317af2f2c8SWarner Losh 	uint8_t  message_args[7];	/* Message Arguments */
12328b8a9b1dSJustin T. Gibbs };
12338b8a9b1dSJustin T. Gibbs 
12348b8a9b1dSJustin T. Gibbs struct ccb_notify_ack {
12358b8a9b1dSJustin T. Gibbs 	struct	  ccb_hdr ccb_h;
12367af2f2c8SWarner Losh 	uint16_t seq_id;		/* Sequence identifier */
12377af2f2c8SWarner Losh 	uint8_t  event;		/* Event flags */
12388b8a9b1dSJustin T. Gibbs };
12398b8a9b1dSJustin T. Gibbs 
12402df76c16SMatt Jacob struct ccb_immediate_notify {
12412df76c16SMatt Jacob 	struct    ccb_hdr ccb_h;
12422df76c16SMatt Jacob 	u_int     tag_id;		/* Tag for immediate notify */
12432df76c16SMatt Jacob 	u_int     seq_id;		/* Tag for target of notify */
12442df76c16SMatt Jacob 	u_int     initiator_id;		/* Initiator Identifier */
12452df76c16SMatt Jacob 	u_int     arg;			/* Function specific */
12462df76c16SMatt Jacob };
12472df76c16SMatt Jacob 
12482df76c16SMatt Jacob struct ccb_notify_acknowledge {
12492df76c16SMatt Jacob 	struct    ccb_hdr ccb_h;
12502df76c16SMatt Jacob 	u_int     tag_id;		/* Tag for immediate notify */
12512df76c16SMatt Jacob 	u_int     seq_id;		/* Tar for target of notify */
12522df76c16SMatt Jacob 	u_int     initiator_id;		/* Initiator Identifier */
125396b5475bSAlexander Motin 	u_int     arg;			/* Response information */
125496b5475bSAlexander Motin 	/*
125596b5475bSAlexander Motin 	 * Lower byte of arg is one of RESPONSE CODE values defined below
125696b5475bSAlexander Motin 	 * (subset of response codes from SPL-4 and FCP-4 specifications),
125796b5475bSAlexander Motin 	 * upper 3 bytes is code-specific ADDITIONAL RESPONSE INFORMATION.
125896b5475bSAlexander Motin 	 */
125996b5475bSAlexander Motin #define	CAM_RSP_TMF_COMPLETE		0x00
126096b5475bSAlexander Motin #define	CAM_RSP_TMF_REJECTED		0x04
126196b5475bSAlexander Motin #define	CAM_RSP_TMF_FAILED		0x05
126296b5475bSAlexander Motin #define	CAM_RSP_TMF_SUCCEEDED		0x08
126396b5475bSAlexander Motin #define	CAM_RSP_TMF_INCORRECT_LUN	0x09
12642df76c16SMatt Jacob };
12652df76c16SMatt Jacob 
12668b8a9b1dSJustin T. Gibbs /* HBA engine structures. */
12678b8a9b1dSJustin T. Gibbs 
12688b8a9b1dSJustin T. Gibbs typedef enum {
12698b8a9b1dSJustin T. Gibbs 	EIT_BUFFER,	/* Engine type: buffer memory */
12708b8a9b1dSJustin T. Gibbs 	EIT_LOSSLESS,	/* Engine type: lossless compression */
12718b8a9b1dSJustin T. Gibbs 	EIT_LOSSY,	/* Engine type: lossy compression */
12728b8a9b1dSJustin T. Gibbs 	EIT_ENCRYPT	/* Engine type: encryption */
12738b8a9b1dSJustin T. Gibbs } ei_type;
12748b8a9b1dSJustin T. Gibbs 
12758b8a9b1dSJustin T. Gibbs typedef enum {
12768b8a9b1dSJustin T. Gibbs 	EAD_VUNIQUE,	/* Engine algorithm ID: vendor unique */
12778b8a9b1dSJustin T. Gibbs 	EAD_LZ1V1,	/* Engine algorithm ID: LZ1 var.1 */
12788b8a9b1dSJustin T. Gibbs 	EAD_LZ2V1,	/* Engine algorithm ID: LZ2 var.1 */
1279273a1a3dSKenneth D. Merry 	EAD_LZ2V2	/* Engine algorithm ID: LZ2 var.2 */
12808b8a9b1dSJustin T. Gibbs } ei_algo;
12818b8a9b1dSJustin T. Gibbs 
12828b8a9b1dSJustin T. Gibbs struct ccb_eng_inq {
12838b8a9b1dSJustin T. Gibbs 	struct	  ccb_hdr ccb_h;
12847af2f2c8SWarner Losh 	uint16_t eng_num;	/* The engine number for this inquiry */
12858b8a9b1dSJustin T. Gibbs 	ei_type   eng_type;	/* Returned engine type */
12868b8a9b1dSJustin T. Gibbs 	ei_algo   eng_algo;	/* Returned engine algorithm type */
12877af2f2c8SWarner Losh 	uint32_t eng_memeory;	/* Returned engine memory size */
12888b8a9b1dSJustin T. Gibbs };
12898b8a9b1dSJustin T. Gibbs 
12908b8a9b1dSJustin T. Gibbs struct ccb_eng_exec {	/* This structure must match SCSIIO size */
12918b8a9b1dSJustin T. Gibbs 	struct	  ccb_hdr ccb_h;
12927af2f2c8SWarner Losh 	uint8_t  *pdrv_ptr;	/* Ptr used by the peripheral driver */
12937af2f2c8SWarner Losh 	uint8_t  *req_map;	/* Ptr for mapping info on the req. */
12947af2f2c8SWarner Losh 	uint8_t  *data_ptr;	/* Pointer to the data buf/SG list */
12957af2f2c8SWarner Losh 	uint32_t dxfer_len;	/* Data transfer length */
12967af2f2c8SWarner Losh 	uint8_t  *engdata_ptr;	/* Pointer to the engine buffer data */
12977af2f2c8SWarner Losh 	uint16_t sglist_cnt;	/* Num of scatter gather list entries */
12987af2f2c8SWarner Losh 	uint32_t dmax_len;	/* Destination data maximum length */
12997af2f2c8SWarner Losh 	uint32_t dest_len;	/* Destination data length */
13008b8a9b1dSJustin T. Gibbs 	int32_t	  src_resid;	/* Source residual length: 2's comp */
13017af2f2c8SWarner Losh 	uint32_t timeout;	/* Timeout value */
13027af2f2c8SWarner Losh 	uint16_t eng_num;	/* Engine number for this request */
13037af2f2c8SWarner Losh 	uint16_t vu_flags;	/* Vendor Unique flags */
13048b8a9b1dSJustin T. Gibbs };
13058b8a9b1dSJustin T. Gibbs 
13068b8a9b1dSJustin T. Gibbs /*
13078b8a9b1dSJustin T. Gibbs  * Definitions for the timeout field in the SCSI I/O CCB.
13088b8a9b1dSJustin T. Gibbs  */
13098b8a9b1dSJustin T. Gibbs #define	CAM_TIME_DEFAULT	0x00000000	/* Use SIM default value */
13108b8a9b1dSJustin T. Gibbs #define	CAM_TIME_INFINITY	0xFFFFFFFF	/* Infinite timeout */
13118b8a9b1dSJustin T. Gibbs 
13128b8a9b1dSJustin T. Gibbs #define	CAM_SUCCESS	0	/* For signaling general success */
13138b8a9b1dSJustin T. Gibbs 
13148b8a9b1dSJustin T. Gibbs #define XPT_CCB_INVALID	-1	/* for signaling a bad CCB to free */
13158b8a9b1dSJustin T. Gibbs 
13168b8a9b1dSJustin T. Gibbs /*
13173501942bSJustin T. Gibbs  * CCB for working with advanced device information.  This operates in a fashion
131806e79492SKenneth D. Merry  * similar to XPT_GDEV_TYPE.  Specify the target in ccb_h, the buffer
131906e79492SKenneth D. Merry  * type requested, and provide a buffer size/buffer to write to.  If the
13203501942bSJustin T. Gibbs  * buffer is too small, provsiz will be larger than bufsiz.
132106e79492SKenneth D. Merry  */
13223501942bSJustin T. Gibbs struct ccb_dev_advinfo {
132306e79492SKenneth D. Merry 	struct ccb_hdr ccb_h;
132406e79492SKenneth D. Merry 	uint32_t flags;
1325e8577fb4SKenneth D. Merry #define	CDAI_FLAG_NONE		0x0	/* No flags set */
13263501942bSJustin T. Gibbs #define	CDAI_FLAG_STORE		0x1	/* If set, action becomes store */
132706e79492SKenneth D. Merry 	uint32_t buftype;		/* IN: Type of data being requested */
132806e79492SKenneth D. Merry 	/* NB: buftype is interpreted on a per-transport basis */
13293501942bSJustin T. Gibbs #define	CDAI_TYPE_SCSI_DEVID	1
13303501942bSJustin T. Gibbs #define	CDAI_TYPE_SERIAL_NUM	2
13313501942bSJustin T. Gibbs #define	CDAI_TYPE_PHYS_PATH	3
1332e6bd5983SKenneth D. Merry #define	CDAI_TYPE_RCAPLONG	4
13333bba3152SKenneth D. Merry #define	CDAI_TYPE_EXT_INQ	5
13349f8ed7e4SWarner Losh #define	CDAI_TYPE_NVME_CNTRL	6	/* NVMe Identify Controller data */
13359f8ed7e4SWarner Losh #define	CDAI_TYPE_NVME_NS	7	/* NVMe Identify Namespace data */
133619641ce8SScott Long #define	CDAI_TYPE_MMC_PARAMS	8	/* MMC/SD ident */
133706e79492SKenneth D. Merry 	off_t bufsiz;			/* IN: Size of external buffer */
133806e79492SKenneth D. Merry #define	CAM_SCSI_DEVID_MAXLEN	65536	/* length in buffer is an uint16_t */
133906e79492SKenneth D. Merry 	off_t provsiz;			/* OUT: Size required/used */
134006e79492SKenneth D. Merry 	uint8_t *buf;			/* IN/OUT: Buffer for requested data */
134106e79492SKenneth D. Merry };
134206e79492SKenneth D. Merry 
134306e79492SKenneth D. Merry /*
1344227d67aaSAlexander Motin  * CCB for sending async events
1345227d67aaSAlexander Motin  */
1346227d67aaSAlexander Motin struct ccb_async {
1347227d67aaSAlexander Motin 	struct ccb_hdr ccb_h;
1348227d67aaSAlexander Motin 	uint32_t async_code;
1349227d67aaSAlexander Motin 	off_t async_arg_size;
1350227d67aaSAlexander Motin 	void *async_arg_ptr;
1351227d67aaSAlexander Motin };
1352227d67aaSAlexander Motin 
1353227d67aaSAlexander Motin /*
13548b8a9b1dSJustin T. Gibbs  * Union of all CCB types for kernel space allocation.  This union should
13558b8a9b1dSJustin T. Gibbs  * never be used for manipulating CCBs - its only use is for the allocation
13568b8a9b1dSJustin T. Gibbs  * and deallocation of raw CCB space and is the return type of xpt_ccb_alloc
13578b8a9b1dSJustin T. Gibbs  * and the argument to xpt_ccb_free.
13588b8a9b1dSJustin T. Gibbs  */
13598b8a9b1dSJustin T. Gibbs union ccb {
13608b8a9b1dSJustin T. Gibbs 	struct	ccb_hdr			ccb_h;	/* For convenience */
13618b8a9b1dSJustin T. Gibbs 	struct	ccb_scsiio		csio;
13628b8a9b1dSJustin T. Gibbs 	struct	ccb_getdev		cgd;
13638b8a9b1dSJustin T. Gibbs 	struct	ccb_getdevlist		cgdl;
13648b8a9b1dSJustin T. Gibbs 	struct	ccb_pathinq		cpi;
13658b8a9b1dSJustin T. Gibbs 	struct	ccb_relsim		crs;
13668b8a9b1dSJustin T. Gibbs 	struct	ccb_setasync		csa;
13678b8a9b1dSJustin T. Gibbs 	struct	ccb_setdev		csd;
136887cfaf0eSJustin T. Gibbs 	struct	ccb_pathstats		cpis;
136987cfaf0eSJustin T. Gibbs 	struct	ccb_getdevstats		cgds;
13708b8a9b1dSJustin T. Gibbs 	struct	ccb_dev_match		cdm;
13718b8a9b1dSJustin T. Gibbs 	struct	ccb_trans_settings	cts;
13728b8a9b1dSJustin T. Gibbs 	struct	ccb_calc_geometry	ccg;
13732df76c16SMatt Jacob 	struct	ccb_sim_knob		knob;
13748b8a9b1dSJustin T. Gibbs 	struct	ccb_abort		cab;
13758b8a9b1dSJustin T. Gibbs 	struct	ccb_resetbus		crb;
13768b8a9b1dSJustin T. Gibbs 	struct	ccb_resetdev		crd;
13778b8a9b1dSJustin T. Gibbs 	struct	ccb_termio		tio;
13788b8a9b1dSJustin T. Gibbs 	struct	ccb_accept_tio		atio;
13798b8a9b1dSJustin T. Gibbs 	struct	ccb_scsiio		ctio;
13808b8a9b1dSJustin T. Gibbs 	struct	ccb_en_lun		cel;
13818b8a9b1dSJustin T. Gibbs 	struct	ccb_immed_notify	cin;
13828b8a9b1dSJustin T. Gibbs 	struct	ccb_notify_ack		cna;
13832df76c16SMatt Jacob 	struct	ccb_immediate_notify	cin1;
13842df76c16SMatt Jacob 	struct	ccb_notify_acknowledge	cna2;
13858b8a9b1dSJustin T. Gibbs 	struct	ccb_eng_inq		cei;
13868b8a9b1dSJustin T. Gibbs 	struct	ccb_eng_exec		cee;
138706e79492SKenneth D. Merry 	struct	ccb_smpio		smpio;
13888b8a9b1dSJustin T. Gibbs 	struct 	ccb_rescan		crcn;
13898b8a9b1dSJustin T. Gibbs 	struct  ccb_debug		cdbg;
139052c9ce25SScott Long 	struct	ccb_ataio		ataio;
13913501942bSJustin T. Gibbs 	struct	ccb_dev_advinfo		cdai;
1392227d67aaSAlexander Motin 	struct	ccb_async		casync;
1393baabaca3SWarner Losh 	struct	ccb_nvmeio		nvmeio;
1394a94a63f0SWarner Losh 	struct	ccb_mmcio		mmcio;
13958b8a9b1dSJustin T. Gibbs };
13968b8a9b1dSJustin T. Gibbs 
139795320aceSDon Lewis #define CCB_CLEAR_ALL_EXCEPT_HDR(ccbp)			\
139895320aceSDon Lewis 	bzero((char *)(ccbp) + sizeof((ccbp)->ccb_h),	\
139995320aceSDon Lewis 	    sizeof(*(ccbp)) - sizeof((ccbp)->ccb_h))
140095320aceSDon Lewis 
14018b8a9b1dSJustin T. Gibbs __BEGIN_DECLS
14028b8a9b1dSJustin T. Gibbs static __inline void
14037af2f2c8SWarner Losh cam_fill_csio(struct ccb_scsiio *csio, uint32_t retries,
14048b8a9b1dSJustin T. Gibbs 	      void (*cbfcnp)(struct cam_periph *, union ccb *),
14057af2f2c8SWarner Losh 	      uint32_t flags, uint8_t tag_action,
14067af2f2c8SWarner Losh 	      uint8_t *data_ptr, uint32_t dxfer_len,
14077af2f2c8SWarner Losh 	      uint8_t sense_len, uint8_t cdb_len,
14087af2f2c8SWarner Losh 	      uint32_t timeout)
14098b8a9b1dSJustin T. Gibbs {
14108b8a9b1dSJustin T. Gibbs 	csio->ccb_h.func_code = XPT_SCSI_IO;
14118b8a9b1dSJustin T. Gibbs 	csio->ccb_h.flags = flags;
1412b5595753SNathan Whitehorn 	csio->ccb_h.xflags = 0;
14138b8a9b1dSJustin T. Gibbs 	csio->ccb_h.retry_count = retries;
14148b8a9b1dSJustin T. Gibbs 	csio->ccb_h.cbfcnp = cbfcnp;
14158b8a9b1dSJustin T. Gibbs 	csio->ccb_h.timeout = timeout;
14168b8a9b1dSJustin T. Gibbs 	csio->data_ptr = data_ptr;
14178b8a9b1dSJustin T. Gibbs 	csio->dxfer_len = dxfer_len;
14188b8a9b1dSJustin T. Gibbs 	csio->sense_len = sense_len;
14198b8a9b1dSJustin T. Gibbs 	csio->cdb_len = cdb_len;
14208b8a9b1dSJustin T. Gibbs 	csio->tag_action = tag_action;
142188364968SAlexander Motin 	csio->priority = 0;
14228532d381SConrad Meyer #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
14238532d381SConrad Meyer 	csio->bio = NULL;
14248532d381SConrad Meyer #endif
14258b8a9b1dSJustin T. Gibbs }
14268b8a9b1dSJustin T. Gibbs 
14278b8a9b1dSJustin T. Gibbs static __inline void
14287af2f2c8SWarner Losh cam_fill_ctio(struct ccb_scsiio *csio, uint32_t retries,
14298b8a9b1dSJustin T. Gibbs 	      void (*cbfcnp)(struct cam_periph *, union ccb *),
14307af2f2c8SWarner Losh 	      uint32_t flags, u_int tag_action, u_int tag_id,
14317af2f2c8SWarner Losh 	      u_int init_id, u_int scsi_status, uint8_t *data_ptr,
14327af2f2c8SWarner Losh 	      uint32_t dxfer_len, uint32_t timeout)
14338b8a9b1dSJustin T. Gibbs {
14348b8a9b1dSJustin T. Gibbs 	csio->ccb_h.func_code = XPT_CONT_TARGET_IO;
14358b8a9b1dSJustin T. Gibbs 	csio->ccb_h.flags = flags;
1436b5595753SNathan Whitehorn 	csio->ccb_h.xflags = 0;
14378b8a9b1dSJustin T. Gibbs 	csio->ccb_h.retry_count = retries;
14388b8a9b1dSJustin T. Gibbs 	csio->ccb_h.cbfcnp = cbfcnp;
14398b8a9b1dSJustin T. Gibbs 	csio->ccb_h.timeout = timeout;
14408b8a9b1dSJustin T. Gibbs 	csio->data_ptr = data_ptr;
14418b8a9b1dSJustin T. Gibbs 	csio->dxfer_len = dxfer_len;
14428b8a9b1dSJustin T. Gibbs 	csio->scsi_status = scsi_status;
14438b8a9b1dSJustin T. Gibbs 	csio->tag_action = tag_action;
144488364968SAlexander Motin 	csio->priority = 0;
14458b8a9b1dSJustin T. Gibbs 	csio->tag_id = tag_id;
14468b8a9b1dSJustin T. Gibbs 	csio->init_id = init_id;
14478b8a9b1dSJustin T. Gibbs }
14488b8a9b1dSJustin T. Gibbs 
144952c9ce25SScott Long static __inline void
14507af2f2c8SWarner Losh cam_fill_ataio(struct ccb_ataio *ataio, uint32_t retries,
145152c9ce25SScott Long 	      void (*cbfcnp)(struct cam_periph *, union ccb *),
14527af2f2c8SWarner Losh 	      uint32_t flags, u_int tag_action __unused,
14537af2f2c8SWarner Losh 	      uint8_t *data_ptr, uint32_t dxfer_len,
14547af2f2c8SWarner Losh 	      uint32_t timeout)
145552c9ce25SScott Long {
145652c9ce25SScott Long 	ataio->ccb_h.func_code = XPT_ATA_IO;
145752c9ce25SScott Long 	ataio->ccb_h.flags = flags;
145852c9ce25SScott Long 	ataio->ccb_h.retry_count = retries;
145952c9ce25SScott Long 	ataio->ccb_h.cbfcnp = cbfcnp;
146052c9ce25SScott Long 	ataio->ccb_h.timeout = timeout;
146152c9ce25SScott Long 	ataio->data_ptr = data_ptr;
146252c9ce25SScott Long 	ataio->dxfer_len = dxfer_len;
1463e4cc6558SWarner Losh 	ataio->ata_flags = 0;
146452c9ce25SScott Long }
146552c9ce25SScott Long 
146606e79492SKenneth D. Merry static __inline void
146706e79492SKenneth D. Merry cam_fill_smpio(struct ccb_smpio *smpio, uint32_t retries,
146806e79492SKenneth D. Merry 	       void (*cbfcnp)(struct cam_periph *, union ccb *), uint32_t flags,
146906e79492SKenneth D. Merry 	       uint8_t *smp_request, int smp_request_len,
147006e79492SKenneth D. Merry 	       uint8_t *smp_response, int smp_response_len,
147106e79492SKenneth D. Merry 	       uint32_t timeout)
147206e79492SKenneth D. Merry {
147306e79492SKenneth D. Merry #ifdef _KERNEL
147406e79492SKenneth D. Merry 	KASSERT((flags & CAM_DIR_MASK) == CAM_DIR_BOTH,
147506e79492SKenneth D. Merry 		("direction != CAM_DIR_BOTH"));
147606e79492SKenneth D. Merry 	KASSERT((smp_request != NULL) && (smp_response != NULL),
147706e79492SKenneth D. Merry 		("need valid request and response buffers"));
147806e79492SKenneth D. Merry 	KASSERT((smp_request_len != 0) && (smp_response_len != 0),
147906e79492SKenneth D. Merry 		("need non-zero request and response lengths"));
148006e79492SKenneth D. Merry #endif /*_KERNEL*/
148106e79492SKenneth D. Merry 	smpio->ccb_h.func_code = XPT_SMP_IO;
148206e79492SKenneth D. Merry 	smpio->ccb_h.flags = flags;
148306e79492SKenneth D. Merry 	smpio->ccb_h.retry_count = retries;
148406e79492SKenneth D. Merry 	smpio->ccb_h.cbfcnp = cbfcnp;
148506e79492SKenneth D. Merry 	smpio->ccb_h.timeout = timeout;
148606e79492SKenneth D. Merry 	smpio->smp_request = smp_request;
148706e79492SKenneth D. Merry 	smpio->smp_request_len = smp_request_len;
148806e79492SKenneth D. Merry 	smpio->smp_response = smp_response;
148906e79492SKenneth D. Merry 	smpio->smp_response_len = smp_response_len;
149006e79492SKenneth D. Merry }
149106e79492SKenneth D. Merry 
1492e64112deSScott Long static __inline void
1493a94a63f0SWarner Losh cam_fill_mmcio(struct ccb_mmcio *mmcio, uint32_t retries,
1494a94a63f0SWarner Losh 	       void (*cbfcnp)(struct cam_periph *, union ccb *), uint32_t flags,
1495a94a63f0SWarner Losh 	       uint32_t mmc_opcode, uint32_t mmc_arg, uint32_t mmc_flags,
1496a94a63f0SWarner Losh 	       struct mmc_data *mmc_d,
1497a94a63f0SWarner Losh 	       uint32_t timeout)
1498a94a63f0SWarner Losh {
1499a94a63f0SWarner Losh 	mmcio->ccb_h.func_code = XPT_MMC_IO;
1500a94a63f0SWarner Losh 	mmcio->ccb_h.flags = flags;
1501a94a63f0SWarner Losh 	mmcio->ccb_h.retry_count = retries;
1502a94a63f0SWarner Losh 	mmcio->ccb_h.cbfcnp = cbfcnp;
1503a94a63f0SWarner Losh 	mmcio->ccb_h.timeout = timeout;
1504a94a63f0SWarner Losh 	mmcio->cmd.opcode = mmc_opcode;
1505a94a63f0SWarner Losh 	mmcio->cmd.arg = mmc_arg;
1506a94a63f0SWarner Losh 	mmcio->cmd.flags = mmc_flags;
1507a94a63f0SWarner Losh 	mmcio->stop.opcode = 0;
1508a94a63f0SWarner Losh 	mmcio->stop.arg = 0;
1509a94a63f0SWarner Losh 	mmcio->stop.flags = 0;
1510a94a63f0SWarner Losh 	if (mmc_d != NULL) {
1511a94a63f0SWarner Losh 		mmcio->cmd.data = mmc_d;
1512a94a63f0SWarner Losh 	} else
1513a94a63f0SWarner Losh 		mmcio->cmd.data = NULL;
1514a94a63f0SWarner Losh 	mmcio->cmd.resp[0] = 0;
1515a94a63f0SWarner Losh 	mmcio->cmd.resp[1] = 0;
1516a94a63f0SWarner Losh 	mmcio->cmd.resp[2] = 0;
1517a94a63f0SWarner Losh 	mmcio->cmd.resp[3] = 0;
1518a94a63f0SWarner Losh }
1519a94a63f0SWarner Losh 
1520a94a63f0SWarner Losh static __inline void
1521e64112deSScott Long cam_set_ccbstatus(union ccb *ccb, cam_status status)
1522e64112deSScott Long {
1523e64112deSScott Long 	ccb->ccb_h.status &= ~CAM_STATUS_MASK;
1524e64112deSScott Long 	ccb->ccb_h.status |= status;
1525e64112deSScott Long }
1526e64112deSScott Long 
1527e64112deSScott Long static __inline cam_status
1528e64112deSScott Long cam_ccb_status(union ccb *ccb)
1529e64112deSScott Long {
153054eb21dbSJung-uk Kim 	return ((cam_status)(ccb->ccb_h.status & CAM_STATUS_MASK));
1531e64112deSScott Long }
1532e64112deSScott Long 
1533fd02926aSWarner Losh static inline bool
1534fd02926aSWarner Losh cam_ccb_success(union ccb *ccb)
1535fd02926aSWarner Losh {
1536fd02926aSWarner Losh 	return (cam_ccb_status(ccb) == CAM_REQ_CMP);
1537fd02926aSWarner Losh }
1538fd02926aSWarner Losh 
1539141bdcc1SNate Lawson void cam_calc_geometry(struct ccb_calc_geometry *ccg, int extended);
1540141bdcc1SNate Lawson 
1541baabaca3SWarner Losh static __inline void
15427af2f2c8SWarner Losh cam_fill_nvmeio(struct ccb_nvmeio *nvmeio, uint32_t retries,
1543baabaca3SWarner Losh 	      void (*cbfcnp)(struct cam_periph *, union ccb *),
15447af2f2c8SWarner Losh 	      uint32_t flags, uint8_t *data_ptr, uint32_t dxfer_len,
15457af2f2c8SWarner Losh 	      uint32_t timeout)
1546baabaca3SWarner Losh {
1547baabaca3SWarner Losh 	nvmeio->ccb_h.func_code = XPT_NVME_IO;
1548baabaca3SWarner Losh 	nvmeio->ccb_h.flags = flags;
1549baabaca3SWarner Losh 	nvmeio->ccb_h.retry_count = retries;
1550baabaca3SWarner Losh 	nvmeio->ccb_h.cbfcnp = cbfcnp;
1551baabaca3SWarner Losh 	nvmeio->ccb_h.timeout = timeout;
1552baabaca3SWarner Losh 	nvmeio->data_ptr = data_ptr;
1553baabaca3SWarner Losh 	nvmeio->dxfer_len = dxfer_len;
1554baabaca3SWarner Losh }
1555df424515SWarner Losh 
1556df424515SWarner Losh static __inline void
15577af2f2c8SWarner Losh cam_fill_nvmeadmin(struct ccb_nvmeio *nvmeio, uint32_t retries,
1558df424515SWarner Losh 	      void (*cbfcnp)(struct cam_periph *, union ccb *),
15597af2f2c8SWarner Losh 	      uint32_t flags, uint8_t *data_ptr, uint32_t dxfer_len,
15607af2f2c8SWarner Losh 	      uint32_t timeout)
1561df424515SWarner Losh {
1562df424515SWarner Losh 	nvmeio->ccb_h.func_code = XPT_NVME_ADMIN;
1563df424515SWarner Losh 	nvmeio->ccb_h.flags = flags;
1564df424515SWarner Losh 	nvmeio->ccb_h.retry_count = retries;
1565df424515SWarner Losh 	nvmeio->ccb_h.cbfcnp = cbfcnp;
1566df424515SWarner Losh 	nvmeio->ccb_h.timeout = timeout;
1567df424515SWarner Losh 	nvmeio->data_ptr = data_ptr;
1568df424515SWarner Losh 	nvmeio->dxfer_len = dxfer_len;
1569df424515SWarner Losh }
15708b8a9b1dSJustin T. Gibbs __END_DECLS
15718b8a9b1dSJustin T. Gibbs 
15728b8a9b1dSJustin T. Gibbs #endif /* _CAM_CAM_CCB_H */
1573