xref: /freebsd/sys/cam/cam_ccb.h (revision 3631c6382fa261edc7d8c7769e72f2ff7201468c)
1898b0535SWarner Losh /*-
28b8a9b1dSJustin T. Gibbs  * Data structures and definitions for CAM Control Blocks (CCBs).
38b8a9b1dSJustin T. Gibbs  *
48b8a9b1dSJustin T. Gibbs  * Copyright (c) 1997, 1998 Justin T. Gibbs.
58b8a9b1dSJustin T. Gibbs  * All rights reserved.
68b8a9b1dSJustin T. Gibbs  *
78b8a9b1dSJustin T. Gibbs  * Redistribution and use in source and binary forms, with or without
88b8a9b1dSJustin T. Gibbs  * modification, are permitted provided that the following conditions
98b8a9b1dSJustin T. Gibbs  * are met:
108b8a9b1dSJustin T. Gibbs  * 1. Redistributions of source code must retain the above copyright
118b8a9b1dSJustin T. Gibbs  *    notice, this list of conditions, and the following disclaimer,
128b8a9b1dSJustin T. Gibbs  *    without modification, immediately at the beginning of the file.
138b8a9b1dSJustin T. Gibbs  * 2. The name of the author may not be used to endorse or promote products
148b8a9b1dSJustin T. Gibbs  *    derived from this software without specific prior written permission.
158b8a9b1dSJustin T. Gibbs  *
168b8a9b1dSJustin T. Gibbs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
178b8a9b1dSJustin T. Gibbs  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
188b8a9b1dSJustin T. Gibbs  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
198b8a9b1dSJustin T. Gibbs  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
208b8a9b1dSJustin T. Gibbs  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
218b8a9b1dSJustin T. Gibbs  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
228b8a9b1dSJustin T. Gibbs  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
238b8a9b1dSJustin T. Gibbs  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
248b8a9b1dSJustin T. Gibbs  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
258b8a9b1dSJustin T. Gibbs  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
268b8a9b1dSJustin T. Gibbs  * SUCH DAMAGE.
278b8a9b1dSJustin T. Gibbs  *
28c3aac50fSPeter Wemm  * $FreeBSD$
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>
358b8a9b1dSJustin T. Gibbs #include <sys/cdefs.h>
3687cfaf0eSJustin T. Gibbs #include <sys/time.h>
37104a9b7eSAlexander Kabaev #include <sys/limits.h>
38c4473420SPeter Wemm #ifndef _KERNEL
398b8a9b1dSJustin T. Gibbs #include <sys/callout.h>
408b8a9b1dSJustin T. Gibbs #endif
418b8a9b1dSJustin T. Gibbs #include <cam/cam_debug.h>
428b8a9b1dSJustin T. Gibbs #include <cam/scsi/scsi_all.h>
4352c9ce25SScott Long #include <cam/ata/ata_all.h>
448b8a9b1dSJustin T. Gibbs 
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 */
588b8a9b1dSJustin T. Gibbs /* CAM CCB flags */
598b8a9b1dSJustin T. Gibbs typedef enum {
608b8a9b1dSJustin T. Gibbs 	CAM_CDB_POINTER		= 0x00000001,/* The CDB field is a pointer    */
618b8a9b1dSJustin T. Gibbs 	CAM_QUEUE_ENABLE	= 0x00000002,/* SIM queue actions are enabled */
628b8a9b1dSJustin T. Gibbs 	CAM_CDB_LINKED		= 0x00000004,/* CCB contains a linked CDB     */
63dd5bac9dSJustin T. Gibbs 	CAM_NEGOTIATE		= 0x00000008,/*
64dd5bac9dSJustin T. Gibbs 					      * Perform transport negotiation
65dd5bac9dSJustin T. Gibbs 					      * with this command.
66dd5bac9dSJustin T. Gibbs 					      */
678b8a9b1dSJustin T. Gibbs 	CAM_SCATTER_VALID	= 0x00000010,/* Scatter/gather list is valid  */
688b8a9b1dSJustin T. Gibbs 	CAM_DIS_AUTOSENSE	= 0x00000020,/* Disable autosense feature     */
6906e79492SKenneth D. Merry 	CAM_DIR_BOTH		= 0x00000000,/* Data direction (00:IN/OUT)    */
708b8a9b1dSJustin T. Gibbs 	CAM_DIR_IN		= 0x00000040,/* Data direction (01:DATA IN)   */
718b8a9b1dSJustin T. Gibbs 	CAM_DIR_OUT		= 0x00000080,/* Data direction (10:DATA OUT)  */
728b8a9b1dSJustin T. Gibbs 	CAM_DIR_NONE		= 0x000000C0,/* Data direction (11:no data)   */
738b8a9b1dSJustin T. Gibbs 	CAM_DIR_MASK		= 0x000000C0,/* Data direction Mask	      */
748b8a9b1dSJustin T. Gibbs 	CAM_SOFT_RST_OP		= 0x00000100,/* Use Soft reset alternative    */
758b8a9b1dSJustin T. Gibbs 	CAM_ENG_SYNC		= 0x00000200,/* Flush resid bytes on complete */
768b8a9b1dSJustin T. Gibbs 	CAM_DEV_QFRZDIS		= 0x00000400,/* Disable DEV Q freezing	      */
778b8a9b1dSJustin T. Gibbs 	CAM_DEV_QFREEZE		= 0x00000800,/* Freeze DEV Q on execution     */
788b8a9b1dSJustin T. Gibbs 	CAM_HIGH_POWER		= 0x00001000,/* Command takes a lot of power  */
798b8a9b1dSJustin T. Gibbs 	CAM_SENSE_PTR		= 0x00002000,/* Sense data is a pointer	      */
808b8a9b1dSJustin T. Gibbs 	CAM_SENSE_PHYS		= 0x00004000,/* Sense pointer is physical addr*/
818b8a9b1dSJustin T. Gibbs 	CAM_TAG_ACTION_VALID	= 0x00008000,/* Use the tag action in this ccb*/
828b8a9b1dSJustin T. Gibbs 	CAM_PASS_ERR_RECOVER	= 0x00010000,/* Pass driver does err. recovery*/
838b8a9b1dSJustin T. Gibbs 	CAM_DIS_DISCONNECT	= 0x00020000,/* Disable disconnect	      */
848b8a9b1dSJustin T. Gibbs 	CAM_SG_LIST_PHYS	= 0x00040000,/* SG list has physical addrs.   */
858b8a9b1dSJustin T. Gibbs 	CAM_MSG_BUF_PHYS	= 0x00080000,/* Message buffer ptr is physical*/
868b8a9b1dSJustin T. Gibbs 	CAM_SNS_BUF_PHYS	= 0x00100000,/* Autosense data ptr is physical*/
878b8a9b1dSJustin T. Gibbs 	CAM_DATA_PHYS		= 0x00200000,/* SG/Buffer data ptrs are phys. */
888b8a9b1dSJustin T. Gibbs 	CAM_CDB_PHYS		= 0x00400000,/* CDB poiner is physical	      */
898b8a9b1dSJustin T. Gibbs 	CAM_ENG_SGLIST		= 0x00800000,/* SG list is for the HBA engine */
908b8a9b1dSJustin T. Gibbs 
918b8a9b1dSJustin T. Gibbs /* Phase cognizant mode flags */
920cdabce0SNick Hibma 	CAM_DIS_AUTOSRP		= 0x01000000,/* Disable autosave/restore ptrs */
938b8a9b1dSJustin T. Gibbs 	CAM_DIS_AUTODISC	= 0x02000000,/* Disable auto disconnect	      */
948b8a9b1dSJustin T. Gibbs 	CAM_TGT_CCB_AVAIL	= 0x04000000,/* Target CCB available	      */
958b8a9b1dSJustin T. Gibbs 	CAM_TGT_PHASE_MODE	= 0x08000000,/* The SIM runs in phase mode    */
96826eb7c8SMatt Jacob 	CAM_MSGB_VALID		= 0x10000000,/* Message buffer valid	      */
97826eb7c8SMatt Jacob 	CAM_STATUS_VALID	= 0x20000000,/* Status buffer valid	      */
98826eb7c8SMatt Jacob 	CAM_DATAB_VALID		= 0x40000000,/* Data buffer valid	      */
998b8a9b1dSJustin T. Gibbs 
1008b8a9b1dSJustin T. Gibbs /* Host target Mode flags */
101826eb7c8SMatt Jacob 	CAM_SEND_SENSE		= 0x08000000,/* Send sense data with status   */
102826eb7c8SMatt Jacob 	CAM_TERM_IO		= 0x10000000,/* Terminate I/O Message sup.    */
103826eb7c8SMatt Jacob 	CAM_DISCONNECT		= 0x20000000,/* Disconnects are mandatory     */
104826eb7c8SMatt Jacob 	CAM_SEND_STATUS		= 0x40000000 /* Send status after data phase  */
1058b8a9b1dSJustin T. Gibbs } ccb_flags;
1068b8a9b1dSJustin T. Gibbs 
1078b8a9b1dSJustin T. Gibbs /* XPT Opcodes for xpt_action */
1088b8a9b1dSJustin T. Gibbs typedef enum {
1099deea857SKenneth D. Merry /* Function code flags are bits greater than 0xff */
1109deea857SKenneth D. Merry 	XPT_FC_QUEUED		= 0x100,
1119deea857SKenneth D. Merry 				/* Non-immediate function code */
1129deea857SKenneth D. Merry 	XPT_FC_USER_CCB		= 0x200,
1139deea857SKenneth D. Merry 	XPT_FC_XPT_ONLY		= 0x400,
1149deea857SKenneth D. Merry 				/* Only for the transport layer device */
115bf8bb7acSJustin T. Gibbs 	XPT_FC_DEV_QUEUED	= 0x800 | XPT_FC_QUEUED,
116bf8bb7acSJustin T. Gibbs 				/* Passes through the device queues */
1178b8a9b1dSJustin T. Gibbs /* Common function commands: 0x00->0x0F */
1189deea857SKenneth D. Merry 	XPT_NOOP 		= 0x00,
1199deea857SKenneth D. Merry 				/* Execute Nothing */
120bf8bb7acSJustin T. Gibbs 	XPT_SCSI_IO		= 0x01 | XPT_FC_DEV_QUEUED,
1219deea857SKenneth D. Merry 				/* Execute the requested I/O operation */
1229deea857SKenneth D. Merry 	XPT_GDEV_TYPE		= 0x02,
1239deea857SKenneth D. Merry 				/* Get type information for specified device */
1249deea857SKenneth D. Merry 	XPT_GDEVLIST		= 0x03,
1259deea857SKenneth D. Merry 				/* Get a list of peripheral devices */
1269deea857SKenneth D. Merry 	XPT_PATH_INQ		= 0x04,
1279deea857SKenneth D. Merry 				/* Path routing inquiry */
1289deea857SKenneth D. Merry 	XPT_REL_SIMQ		= 0x05,
12983c5d981SAlexander Motin 				/* Release a frozen device queue */
1309deea857SKenneth D. Merry 	XPT_SASYNC_CB		= 0x06,
1319deea857SKenneth D. Merry 				/* Set Asynchronous Callback Parameters */
1329deea857SKenneth D. Merry 	XPT_SDEV_TYPE		= 0x07,
1339deea857SKenneth D. Merry 				/* Set device type information */
1349deea857SKenneth D. Merry 	XPT_SCAN_BUS		= 0x08 | XPT_FC_QUEUED | XPT_FC_USER_CCB
1359deea857SKenneth D. Merry 				       | XPT_FC_XPT_ONLY,
1369deea857SKenneth D. Merry 				/* (Re)Scan the SCSI Bus */
1379deea857SKenneth D. Merry 	XPT_DEV_MATCH		= 0x09 | XPT_FC_XPT_ONLY,
1389deea857SKenneth D. Merry 				/* Get EDT entries matching the given pattern */
1399deea857SKenneth D. Merry 	XPT_DEBUG		= 0x0a,
1409deea857SKenneth D. Merry 				/* Turn on debugging for a bus, target or lun */
14187cfaf0eSJustin T. Gibbs 	XPT_PATH_STATS		= 0x0b,
14287cfaf0eSJustin T. Gibbs 				/* Path statistics (error counts, etc.) */
14387cfaf0eSJustin T. Gibbs 	XPT_GDEV_STATS		= 0x0c,
14487cfaf0eSJustin T. Gibbs 				/* Device statistics (error counts, etc.) */
14583c5d981SAlexander Motin 	XPT_FREEZE_QUEUE	= 0x0d,
14683c5d981SAlexander Motin 				/* Freeze device queue */
1473501942bSJustin T. Gibbs 	XPT_DEV_ADVINFO		= 0x0e,
1483501942bSJustin T. Gibbs 				/* Get/Set Device advanced information */
1498b8a9b1dSJustin T. Gibbs /* SCSI Control Functions: 0x10->0x1F */
1509deea857SKenneth D. Merry 	XPT_ABORT		= 0x10,
1519deea857SKenneth D. Merry 				/* Abort the specified CCB */
1529deea857SKenneth D. Merry 	XPT_RESET_BUS		= 0x11 | XPT_FC_XPT_ONLY,
1539deea857SKenneth D. Merry 				/* Reset the specified SCSI bus */
154bf8bb7acSJustin T. Gibbs 	XPT_RESET_DEV		= 0x12 | XPT_FC_DEV_QUEUED,
1559deea857SKenneth D. Merry 				/* Bus Device Reset the specified SCSI device */
1569deea857SKenneth D. Merry 	XPT_TERM_IO		= 0x13,
1579deea857SKenneth D. Merry 				/* Terminate the I/O process */
1589deea857SKenneth D. Merry 	XPT_SCAN_LUN		= 0x14 | XPT_FC_QUEUED | XPT_FC_USER_CCB
1599deea857SKenneth D. Merry 				       | XPT_FC_XPT_ONLY,
1609deea857SKenneth D. Merry 				/* Scan Logical Unit */
1619deea857SKenneth D. Merry 	XPT_GET_TRAN_SETTINGS	= 0x15,
1629deea857SKenneth D. Merry 				/*
1638b8a9b1dSJustin T. Gibbs 				 * Get default/user transfer settings
1648b8a9b1dSJustin T. Gibbs 				 * for the target
1658b8a9b1dSJustin T. Gibbs 				 */
1669deea857SKenneth D. Merry 	XPT_SET_TRAN_SETTINGS	= 0x16,
1679deea857SKenneth D. Merry 				/*
1688b8a9b1dSJustin T. Gibbs 				 * Set transfer rate/width
1698b8a9b1dSJustin T. Gibbs 				 * negotiation settings
1708b8a9b1dSJustin T. Gibbs 				 */
1719deea857SKenneth D. Merry 	XPT_CALC_GEOMETRY	= 0x17,
1729deea857SKenneth D. Merry 				/*
1738b8a9b1dSJustin T. Gibbs 				 * Calculate the geometry parameters for
1748b8a9b1dSJustin T. Gibbs 				 * a device give the sector size and
1758b8a9b1dSJustin T. Gibbs 				 * volume size.
1768b8a9b1dSJustin T. Gibbs 				 */
17752c9ce25SScott Long 	XPT_ATA_IO		= 0x18 | XPT_FC_DEV_QUEUED,
17852c9ce25SScott Long 				/* Execute the requested ATA I/O operation */
1798b8a9b1dSJustin T. Gibbs 
1802df76c16SMatt Jacob 	XPT_GET_SIM_KNOB	= 0x18,
1812df76c16SMatt Jacob 				/*
1822df76c16SMatt Jacob 				 * Get SIM specific knob values.
1832df76c16SMatt Jacob 				 */
1842df76c16SMatt Jacob 
1852df76c16SMatt Jacob 	XPT_SET_SIM_KNOB	= 0x19,
1862df76c16SMatt Jacob 				/*
1872df76c16SMatt Jacob 				 * Set SIM specific knob values.
1882df76c16SMatt Jacob 				 */
1890e85f214SMatt Jacob 
19006e79492SKenneth D. Merry 	XPT_SMP_IO		= 0x1b | XPT_FC_DEV_QUEUED,
19106e79492SKenneth D. Merry 				/* Serial Management Protocol */
19206e79492SKenneth D. Merry 
1930e85f214SMatt Jacob 	XPT_SCAN_TGT		= 0x1E | XPT_FC_QUEUED | XPT_FC_USER_CCB
1940e85f214SMatt Jacob 				       | XPT_FC_XPT_ONLY,
1950e85f214SMatt Jacob 				/* Scan Target */
1960e85f214SMatt Jacob 
1978b8a9b1dSJustin T. Gibbs /* HBA engine commands 0x20->0x2F */
1989deea857SKenneth D. Merry 	XPT_ENG_INQ		= 0x20 | XPT_FC_XPT_ONLY,
1999deea857SKenneth D. Merry 				/* HBA engine feature inquiry */
2003393f8daSKenneth D. Merry 	XPT_ENG_EXEC		= 0x21 | XPT_FC_DEV_QUEUED,
2019deea857SKenneth D. Merry 				/* HBA execute engine request */
2028b8a9b1dSJustin T. Gibbs 
2038b8a9b1dSJustin T. Gibbs /* Target mode commands: 0x30->0x3F */
2049deea857SKenneth D. Merry 	XPT_EN_LUN		= 0x30,
2059deea857SKenneth D. Merry 				/* Enable LUN as a target */
206bf8bb7acSJustin T. Gibbs 	XPT_TARGET_IO		= 0x31 | XPT_FC_DEV_QUEUED,
2079deea857SKenneth D. Merry 				/* Execute target I/O request */
2089deea857SKenneth D. Merry 	XPT_ACCEPT_TARGET_IO	= 0x32 | XPT_FC_QUEUED | XPT_FC_USER_CCB,
2099deea857SKenneth D. Merry 				/* Accept Host Target Mode CDB */
210bf8bb7acSJustin T. Gibbs 	XPT_CONT_TARGET_IO	= 0x33 | XPT_FC_DEV_QUEUED,
2119deea857SKenneth D. Merry 				/* Continue Host Target I/O Connection */
2129deea857SKenneth D. Merry 	XPT_IMMED_NOTIFY	= 0x34 | XPT_FC_QUEUED | XPT_FC_USER_CCB,
2132df76c16SMatt Jacob 				/* Notify Host Target driver of event (obsolete) */
2149deea857SKenneth D. Merry 	XPT_NOTIFY_ACK		= 0x35,
2152df76c16SMatt Jacob 				/* Acknowledgement of event (obsolete) */
2162df76c16SMatt Jacob 	XPT_IMMEDIATE_NOTIFY	= 0x36 | XPT_FC_QUEUED | XPT_FC_USER_CCB,
2172df76c16SMatt Jacob 				/* Notify Host Target driver of event */
2182df76c16SMatt Jacob 	XPT_NOTIFY_ACKNOWLEDGE	= 0x37 | XPT_FC_QUEUED | XPT_FC_USER_CCB,
2199deea857SKenneth D. Merry 				/* Acknowledgement of event */
2208b8a9b1dSJustin T. Gibbs 
2218b8a9b1dSJustin T. Gibbs /* Vendor Unique codes: 0x80->0x8F */
2228b8a9b1dSJustin T. Gibbs 	XPT_VUNIQUE		= 0x80
2238b8a9b1dSJustin T. Gibbs } xpt_opcode;
2248b8a9b1dSJustin T. Gibbs 
2259deea857SKenneth D. Merry #define XPT_FC_GROUP_MASK		0xF0
2269deea857SKenneth D. Merry #define XPT_FC_GROUP(op) ((op) & XPT_FC_GROUP_MASK)
2279deea857SKenneth D. Merry #define XPT_FC_GROUP_COMMON		0x00
2289deea857SKenneth D. Merry #define XPT_FC_GROUP_SCSI_CONTROL	0x10
2299deea857SKenneth D. Merry #define XPT_FC_GROUP_HBA_ENGINE		0x20
2309deea857SKenneth D. Merry #define XPT_FC_GROUP_TMODE		0x30
2319deea857SKenneth D. Merry #define XPT_FC_GROUP_VENDOR_UNIQUE	0x80
232a89bb8b4SJustin T. Gibbs 
233bf8bb7acSJustin T. Gibbs #define XPT_FC_IS_DEV_QUEUED(ccb) 	\
234bf8bb7acSJustin T. Gibbs     (((ccb)->ccb_h.func_code & XPT_FC_DEV_QUEUED) == XPT_FC_DEV_QUEUED)
235bf8bb7acSJustin T. Gibbs #define XPT_FC_IS_QUEUED(ccb) 	\
236bf8bb7acSJustin T. Gibbs     (((ccb)->ccb_h.func_code & XPT_FC_QUEUED) != 0)
2373393f8daSKenneth D. Merry 
2383393f8daSKenneth D. Merry typedef enum {
2393393f8daSKenneth D. Merry 	PROTO_UNKNOWN,
2403393f8daSKenneth D. Merry 	PROTO_UNSPECIFIED,
2413393f8daSKenneth D. Merry 	PROTO_SCSI,	/* Small Computer System Interface */
2423393f8daSKenneth D. Merry 	PROTO_ATA,	/* AT Attachment */
2433393f8daSKenneth D. Merry 	PROTO_ATAPI,	/* AT Attachment Packetized Interface */
24452c9ce25SScott Long 	PROTO_SATAPM,	/* SATA Port Multiplier */
2453089bb2eSAlexander Motin 	PROTO_SEMB,	/* SATA Enclosure Management Bridge */
2463393f8daSKenneth D. Merry } cam_proto;
2473393f8daSKenneth D. Merry 
2483393f8daSKenneth D. Merry typedef enum {
2493393f8daSKenneth D. Merry 	XPORT_UNKNOWN,
2503393f8daSKenneth D. Merry 	XPORT_UNSPECIFIED,
2513393f8daSKenneth D. Merry 	XPORT_SPI,	/* SCSI Parallel Interface */
2523393f8daSKenneth D. Merry 	XPORT_FC,	/* Fiber Channel */
2533393f8daSKenneth D. Merry 	XPORT_SSA,	/* Serial Storage Architecture */
2543393f8daSKenneth D. Merry 	XPORT_USB,	/* Universal Serial Bus */
2553393f8daSKenneth D. Merry 	XPORT_PPB,	/* Parallel Port Bus */
256c4270cb6SMatt Jacob 	XPORT_ATA,	/* AT Attachment */
257c4270cb6SMatt Jacob 	XPORT_SAS,	/* Serial Attached SCSI */
25852c9ce25SScott Long 	XPORT_SATA,	/* Serial AT Attachment */
25933ea30feSAlexander Motin 	XPORT_ISCSI,	/* iSCSI */
2603393f8daSKenneth D. Merry } cam_xport;
2613393f8daSKenneth D. Merry 
262b8b6b5d3SAlexander Motin #define XPORT_IS_ATA(t)		((t) == XPORT_ATA || (t) == XPORT_SATA)
263b8b6b5d3SAlexander Motin #define XPORT_IS_SCSI(t)	((t) != XPORT_UNKNOWN && \
264b8b6b5d3SAlexander Motin 				 (t) != XPORT_UNSPECIFIED && \
265b8b6b5d3SAlexander Motin 				 !XPORT_IS_ATA(t))
266b8b6b5d3SAlexander Motin #define XPORT_DEVSTAT_TYPE(t)	(XPORT_IS_ATA(t) ? DEVSTAT_TYPE_IF_IDE : \
267b8b6b5d3SAlexander Motin 				 XPORT_IS_SCSI(t) ? DEVSTAT_TYPE_IF_SCSI : \
268b8b6b5d3SAlexander Motin 				 DEVSTAT_TYPE_IF_OTHER)
269b8b6b5d3SAlexander Motin 
2703393f8daSKenneth D. Merry #define PROTO_VERSION_UNKNOWN (UINT_MAX - 1)
2713393f8daSKenneth D. Merry #define PROTO_VERSION_UNSPECIFIED UINT_MAX
2723393f8daSKenneth D. Merry #define XPORT_VERSION_UNKNOWN (UINT_MAX - 1)
2733393f8daSKenneth D. Merry #define XPORT_VERSION_UNSPECIFIED UINT_MAX
2743393f8daSKenneth D. Merry 
2758b8a9b1dSJustin T. Gibbs typedef union {
276e3975643SJake Burkholder 	LIST_ENTRY(ccb_hdr) le;
277e3975643SJake Burkholder 	SLIST_ENTRY(ccb_hdr) sle;
278e3975643SJake Burkholder 	TAILQ_ENTRY(ccb_hdr) tqe;
279e3975643SJake Burkholder 	STAILQ_ENTRY(ccb_hdr) stqe;
2808b8a9b1dSJustin T. Gibbs } camq_entry;
2818b8a9b1dSJustin T. Gibbs 
2828b8a9b1dSJustin T. Gibbs typedef union {
2838b8a9b1dSJustin T. Gibbs 	void		*ptr;
2848b8a9b1dSJustin T. Gibbs 	u_long		field;
2852b83592fSScott Long 	u_int8_t	bytes[sizeof(uintptr_t)];
2868b8a9b1dSJustin T. Gibbs } ccb_priv_entry;
2878b8a9b1dSJustin T. Gibbs 
2888b8a9b1dSJustin T. Gibbs typedef union {
2898b8a9b1dSJustin T. Gibbs 	ccb_priv_entry	entries[CCB_PERIPH_PRIV_SIZE];
2908b8a9b1dSJustin T. Gibbs 	u_int8_t	bytes[CCB_PERIPH_PRIV_SIZE * sizeof(ccb_priv_entry)];
2918b8a9b1dSJustin T. Gibbs } ccb_ppriv_area;
2928b8a9b1dSJustin T. Gibbs 
2938b8a9b1dSJustin T. Gibbs typedef union {
2948b8a9b1dSJustin T. Gibbs 	ccb_priv_entry	entries[CCB_SIM_PRIV_SIZE];
2958b8a9b1dSJustin T. Gibbs 	u_int8_t	bytes[CCB_SIM_PRIV_SIZE * sizeof(ccb_priv_entry)];
2968b8a9b1dSJustin T. Gibbs } ccb_spriv_area;
2978b8a9b1dSJustin T. Gibbs 
2988b8a9b1dSJustin T. Gibbs struct ccb_hdr {
2998b8a9b1dSJustin T. Gibbs 	cam_pinfo	pinfo;		/* Info for priority scheduling */
3008b8a9b1dSJustin T. Gibbs 	camq_entry	xpt_links;	/* For chaining in the XPT layer */
3018b8a9b1dSJustin T. Gibbs 	camq_entry	sim_links;	/* For chaining in the SIM layer */
3028b8a9b1dSJustin T. Gibbs 	camq_entry	periph_links;	/* For chaining in the type driver */
3038b8a9b1dSJustin T. Gibbs 	u_int32_t	retry_count;
3048b8a9b1dSJustin T. Gibbs 	void		(*cbfcnp)(struct cam_periph *, union ccb *);
305af693a70SScott Long 					/* Callback on completion function */
3068b8a9b1dSJustin T. Gibbs 	xpt_opcode	func_code;	/* XPT function code */
3078b8a9b1dSJustin T. Gibbs 	u_int32_t	status;		/* Status returned by CAM subsystem */
308af693a70SScott Long 	struct		cam_path *path;	/* Compiled path for this ccb */
3098b8a9b1dSJustin T. Gibbs 	path_id_t	path_id;	/* Path ID for the request */
3108b8a9b1dSJustin T. Gibbs 	target_id_t	target_id;	/* Target device ID */
3118b8a9b1dSJustin T. Gibbs 	lun_id_t	target_lun;	/* Target LUN number */
312af693a70SScott Long 	u_int32_t	flags;		/* ccb_flags */
3138b8a9b1dSJustin T. Gibbs 	ccb_ppriv_area	periph_priv;
3148b8a9b1dSJustin T. Gibbs 	ccb_spriv_area	sim_priv;
3158b8a9b1dSJustin T. Gibbs 	u_int32_t	timeout;	/* Timeout value */
3162b83592fSScott Long 
3172b83592fSScott Long 	/*
3182b83592fSScott Long 	 * Deprecated, only for use by non-MPSAFE SIMs.  All others must
3192b83592fSScott Long 	 * allocate and initialize their own callout storage.
3202b83592fSScott Long 	 */
3218b8a9b1dSJustin T. Gibbs 	struct		callout_handle timeout_ch;
3228b8a9b1dSJustin T. Gibbs };
3238b8a9b1dSJustin T. Gibbs 
3248b8a9b1dSJustin T. Gibbs /* Get Device Information CCB */
3258b8a9b1dSJustin T. Gibbs struct ccb_getdev {
3268b8a9b1dSJustin T. Gibbs 	struct	  ccb_hdr ccb_h;
32752c9ce25SScott Long 	cam_proto protocol;
3288b8a9b1dSJustin T. Gibbs 	struct scsi_inquiry_data inq_data;
32952c9ce25SScott Long 	struct ata_params ident_data;
3308b8a9b1dSJustin T. Gibbs 	u_int8_t  serial_num[252];
33130a4094fSAlexander Motin 	u_int8_t  inq_flags;
3328b8a9b1dSJustin T. Gibbs 	u_int8_t  serial_num_len;
3338b8a9b1dSJustin T. Gibbs };
3348b8a9b1dSJustin T. Gibbs 
33587cfaf0eSJustin T. Gibbs /* Device Statistics CCB */
33687cfaf0eSJustin T. Gibbs struct ccb_getdevstats {
33787cfaf0eSJustin T. Gibbs 	struct	ccb_hdr	ccb_h;
33887cfaf0eSJustin T. Gibbs 	int	dev_openings;	/* Space left for more work on device*/
33987cfaf0eSJustin T. Gibbs 	int	dev_active;	/* Transactions running on the device */
34087cfaf0eSJustin T. Gibbs 	int	devq_openings;	/* Space left for more queued work */
34187cfaf0eSJustin T. Gibbs 	int	devq_queued;	/* Transactions queued to be sent */
34287cfaf0eSJustin T. Gibbs 	int	held;		/*
34387cfaf0eSJustin T. Gibbs 				 * CCBs held by peripheral drivers
34487cfaf0eSJustin T. Gibbs 				 * for this device
34587cfaf0eSJustin T. Gibbs 				 */
34682815562SJustin T. Gibbs 	int	maxtags;	/*
34782815562SJustin T. Gibbs 				 * Boundary conditions for number of
34882815562SJustin T. Gibbs 				 * tagged operations
34982815562SJustin T. Gibbs 				 */
35082815562SJustin T. Gibbs 	int	mintags;
35187cfaf0eSJustin T. Gibbs 	struct	timeval last_reset;	/* Time of last bus reset/loop init */
35287cfaf0eSJustin T. Gibbs };
3538b8a9b1dSJustin T. Gibbs 
3548b8a9b1dSJustin T. Gibbs typedef enum {
3558b8a9b1dSJustin T. Gibbs 	CAM_GDEVLIST_LAST_DEVICE,
3568b8a9b1dSJustin T. Gibbs 	CAM_GDEVLIST_LIST_CHANGED,
3578b8a9b1dSJustin T. Gibbs 	CAM_GDEVLIST_MORE_DEVS,
3588b8a9b1dSJustin T. Gibbs 	CAM_GDEVLIST_ERROR
3598b8a9b1dSJustin T. Gibbs } ccb_getdevlist_status_e;
3608b8a9b1dSJustin T. Gibbs 
3618b8a9b1dSJustin T. Gibbs struct ccb_getdevlist {
3628b8a9b1dSJustin T. Gibbs 	struct ccb_hdr		ccb_h;
3638b8a9b1dSJustin T. Gibbs 	char 			periph_name[DEV_IDLEN];
3648b8a9b1dSJustin T. Gibbs 	u_int32_t		unit_number;
3658b8a9b1dSJustin T. Gibbs 	unsigned int		generation;
3668b8a9b1dSJustin T. Gibbs 	u_int32_t		index;
3678b8a9b1dSJustin T. Gibbs 	ccb_getdevlist_status_e	status;
3688b8a9b1dSJustin T. Gibbs };
3698b8a9b1dSJustin T. Gibbs 
3708b8a9b1dSJustin T. Gibbs typedef enum {
3718b8a9b1dSJustin T. Gibbs 	PERIPH_MATCH_NONE	= 0x000,
3728b8a9b1dSJustin T. Gibbs 	PERIPH_MATCH_PATH	= 0x001,
3738b8a9b1dSJustin T. Gibbs 	PERIPH_MATCH_TARGET	= 0x002,
3748b8a9b1dSJustin T. Gibbs 	PERIPH_MATCH_LUN	= 0x004,
3758b8a9b1dSJustin T. Gibbs 	PERIPH_MATCH_NAME	= 0x008,
3768b8a9b1dSJustin T. Gibbs 	PERIPH_MATCH_UNIT	= 0x010,
3778b8a9b1dSJustin T. Gibbs 	PERIPH_MATCH_ANY	= 0x01f
3788b8a9b1dSJustin T. Gibbs } periph_pattern_flags;
3798b8a9b1dSJustin T. Gibbs 
3808b8a9b1dSJustin T. Gibbs struct periph_match_pattern {
3818b8a9b1dSJustin T. Gibbs 	char			periph_name[DEV_IDLEN];
3828b8a9b1dSJustin T. Gibbs 	u_int32_t		unit_number;
3838b8a9b1dSJustin T. Gibbs 	path_id_t		path_id;
3848b8a9b1dSJustin T. Gibbs 	target_id_t		target_id;
3858b8a9b1dSJustin T. Gibbs 	lun_id_t		target_lun;
3868b8a9b1dSJustin T. Gibbs 	periph_pattern_flags	flags;
3878b8a9b1dSJustin T. Gibbs };
3888b8a9b1dSJustin T. Gibbs 
3898b8a9b1dSJustin T. Gibbs typedef enum {
3908b8a9b1dSJustin T. Gibbs 	DEV_MATCH_NONE		= 0x000,
3918b8a9b1dSJustin T. Gibbs 	DEV_MATCH_PATH		= 0x001,
3928b8a9b1dSJustin T. Gibbs 	DEV_MATCH_TARGET	= 0x002,
3938b8a9b1dSJustin T. Gibbs 	DEV_MATCH_LUN		= 0x004,
3948b8a9b1dSJustin T. Gibbs 	DEV_MATCH_INQUIRY	= 0x008,
3953501942bSJustin T. Gibbs 	DEV_MATCH_DEVID		= 0x010,
3968b8a9b1dSJustin T. Gibbs 	DEV_MATCH_ANY		= 0x00f
3978b8a9b1dSJustin T. Gibbs } dev_pattern_flags;
3988b8a9b1dSJustin T. Gibbs 
3993501942bSJustin T. Gibbs struct device_id_match_pattern {
4003501942bSJustin T. Gibbs 	uint8_t id_len;
4013501942bSJustin T. Gibbs 	uint8_t id[256];
4023501942bSJustin T. Gibbs };
4033501942bSJustin T. Gibbs 
4048b8a9b1dSJustin T. Gibbs struct device_match_pattern {
4058b8a9b1dSJustin T. Gibbs 	path_id_t					path_id;
4068b8a9b1dSJustin T. Gibbs 	target_id_t					target_id;
4078b8a9b1dSJustin T. Gibbs 	lun_id_t					target_lun;
4088b8a9b1dSJustin T. Gibbs 	dev_pattern_flags				flags;
4093501942bSJustin T. Gibbs 	union {
4103501942bSJustin T. Gibbs 		struct scsi_static_inquiry_pattern	inq_pat;
4113501942bSJustin T. Gibbs 		struct device_id_match_pattern		devid_pat;
4123501942bSJustin T. Gibbs 	} data;
4138b8a9b1dSJustin T. Gibbs };
4148b8a9b1dSJustin T. Gibbs 
4158b8a9b1dSJustin T. Gibbs typedef enum {
4168b8a9b1dSJustin T. Gibbs 	BUS_MATCH_NONE		= 0x000,
4178b8a9b1dSJustin T. Gibbs 	BUS_MATCH_PATH		= 0x001,
4188b8a9b1dSJustin T. Gibbs 	BUS_MATCH_NAME		= 0x002,
4198b8a9b1dSJustin T. Gibbs 	BUS_MATCH_UNIT		= 0x004,
4208b8a9b1dSJustin T. Gibbs 	BUS_MATCH_BUS_ID	= 0x008,
4218b8a9b1dSJustin T. Gibbs 	BUS_MATCH_ANY		= 0x00f
4228b8a9b1dSJustin T. Gibbs } bus_pattern_flags;
4238b8a9b1dSJustin T. Gibbs 
4248b8a9b1dSJustin T. Gibbs struct bus_match_pattern {
4258b8a9b1dSJustin T. Gibbs 	path_id_t		path_id;
4268b8a9b1dSJustin T. Gibbs 	char			dev_name[DEV_IDLEN];
4278b8a9b1dSJustin T. Gibbs 	u_int32_t		unit_number;
4288b8a9b1dSJustin T. Gibbs 	u_int32_t		bus_id;
4298b8a9b1dSJustin T. Gibbs 	bus_pattern_flags	flags;
4308b8a9b1dSJustin T. Gibbs };
4318b8a9b1dSJustin T. Gibbs 
4328b8a9b1dSJustin T. Gibbs union match_pattern {
4338b8a9b1dSJustin T. Gibbs 	struct periph_match_pattern	periph_pattern;
4348b8a9b1dSJustin T. Gibbs 	struct device_match_pattern	device_pattern;
4358b8a9b1dSJustin T. Gibbs 	struct bus_match_pattern	bus_pattern;
4368b8a9b1dSJustin T. Gibbs };
4378b8a9b1dSJustin T. Gibbs 
4388b8a9b1dSJustin T. Gibbs typedef enum {
4398b8a9b1dSJustin T. Gibbs 	DEV_MATCH_PERIPH,
4408b8a9b1dSJustin T. Gibbs 	DEV_MATCH_DEVICE,
4418b8a9b1dSJustin T. Gibbs 	DEV_MATCH_BUS
4428b8a9b1dSJustin T. Gibbs } dev_match_type;
4438b8a9b1dSJustin T. Gibbs 
4448b8a9b1dSJustin T. Gibbs struct dev_match_pattern {
4458b8a9b1dSJustin T. Gibbs 	dev_match_type		type;
4468b8a9b1dSJustin T. Gibbs 	union match_pattern	pattern;
4478b8a9b1dSJustin T. Gibbs };
4488b8a9b1dSJustin T. Gibbs 
4498b8a9b1dSJustin T. Gibbs struct periph_match_result {
4508b8a9b1dSJustin T. Gibbs 	char			periph_name[DEV_IDLEN];
4518b8a9b1dSJustin T. Gibbs 	u_int32_t		unit_number;
4528b8a9b1dSJustin T. Gibbs 	path_id_t		path_id;
4538b8a9b1dSJustin T. Gibbs 	target_id_t		target_id;
4548b8a9b1dSJustin T. Gibbs 	lun_id_t		target_lun;
4558b8a9b1dSJustin T. Gibbs };
4568b8a9b1dSJustin T. Gibbs 
4579deea857SKenneth D. Merry typedef enum {
4589deea857SKenneth D. Merry 	DEV_RESULT_NOFLAG		= 0x00,
4599deea857SKenneth D. Merry 	DEV_RESULT_UNCONFIGURED		= 0x01
4609deea857SKenneth D. Merry } dev_result_flags;
4619deea857SKenneth D. Merry 
4628b8a9b1dSJustin T. Gibbs struct device_match_result {
4638b8a9b1dSJustin T. Gibbs 	path_id_t			path_id;
4648b8a9b1dSJustin T. Gibbs 	target_id_t			target_id;
4658b8a9b1dSJustin T. Gibbs 	lun_id_t			target_lun;
46652c9ce25SScott Long 	cam_proto			protocol;
4678b8a9b1dSJustin T. Gibbs 	struct scsi_inquiry_data	inq_data;
46852c9ce25SScott Long 	struct ata_params		ident_data;
4699deea857SKenneth D. Merry 	dev_result_flags		flags;
4708b8a9b1dSJustin T. Gibbs };
4718b8a9b1dSJustin T. Gibbs 
4728b8a9b1dSJustin T. Gibbs struct bus_match_result {
4738b8a9b1dSJustin T. Gibbs 	path_id_t	path_id;
4748b8a9b1dSJustin T. Gibbs 	char		dev_name[DEV_IDLEN];
4758b8a9b1dSJustin T. Gibbs 	u_int32_t	unit_number;
4768b8a9b1dSJustin T. Gibbs 	u_int32_t	bus_id;
4778b8a9b1dSJustin T. Gibbs };
4788b8a9b1dSJustin T. Gibbs 
4798b8a9b1dSJustin T. Gibbs union match_result {
4808b8a9b1dSJustin T. Gibbs 	struct periph_match_result	periph_result;
4818b8a9b1dSJustin T. Gibbs 	struct device_match_result	device_result;
4828b8a9b1dSJustin T. Gibbs 	struct bus_match_result		bus_result;
4838b8a9b1dSJustin T. Gibbs };
4848b8a9b1dSJustin T. Gibbs 
4858b8a9b1dSJustin T. Gibbs struct dev_match_result {
4868b8a9b1dSJustin T. Gibbs 	dev_match_type		type;
4878b8a9b1dSJustin T. Gibbs 	union match_result	result;
4888b8a9b1dSJustin T. Gibbs };
4898b8a9b1dSJustin T. Gibbs 
4908b8a9b1dSJustin T. Gibbs typedef enum {
4918b8a9b1dSJustin T. Gibbs 	CAM_DEV_MATCH_LAST,
4928b8a9b1dSJustin T. Gibbs 	CAM_DEV_MATCH_MORE,
4938b8a9b1dSJustin T. Gibbs 	CAM_DEV_MATCH_LIST_CHANGED,
4948b8a9b1dSJustin T. Gibbs 	CAM_DEV_MATCH_SIZE_ERROR,
4958b8a9b1dSJustin T. Gibbs 	CAM_DEV_MATCH_ERROR
4968b8a9b1dSJustin T. Gibbs } ccb_dev_match_status;
4978b8a9b1dSJustin T. Gibbs 
4988b8a9b1dSJustin T. Gibbs typedef enum {
4998b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_NONE	= 0x000,
5008b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_BUS		= 0x001,
5018b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_TARGET	= 0x002,
5028b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_DEVICE	= 0x004,
5038b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_PERIPH	= 0x008,
5048b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_PDPTR	= 0x010,
5058b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_TYPEMASK	= 0xf00,
5068b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_EDT		= 0x100,
5078b8a9b1dSJustin T. Gibbs 	CAM_DEV_POS_PDRV	= 0x200
5088b8a9b1dSJustin T. Gibbs } dev_pos_type;
5098b8a9b1dSJustin T. Gibbs 
5108b8a9b1dSJustin T. Gibbs struct ccb_dm_cookie {
5118b8a9b1dSJustin T. Gibbs 	void 	*bus;
5128b8a9b1dSJustin T. Gibbs 	void	*target;
5138b8a9b1dSJustin T. Gibbs 	void	*device;
5148b8a9b1dSJustin T. Gibbs 	void	*periph;
5158b8a9b1dSJustin T. Gibbs 	void	*pdrv;
5168b8a9b1dSJustin T. Gibbs };
5178b8a9b1dSJustin T. Gibbs 
5188b8a9b1dSJustin T. Gibbs struct ccb_dev_position {
5198b8a9b1dSJustin T. Gibbs 	u_int			generations[4];
5208b8a9b1dSJustin T. Gibbs #define	CAM_BUS_GENERATION	0x00
5218b8a9b1dSJustin T. Gibbs #define CAM_TARGET_GENERATION	0x01
5228b8a9b1dSJustin T. Gibbs #define CAM_DEV_GENERATION	0x02
5238b8a9b1dSJustin T. Gibbs #define CAM_PERIPH_GENERATION	0x03
5248b8a9b1dSJustin T. Gibbs 	dev_pos_type		position_type;
5258b8a9b1dSJustin T. Gibbs 	struct ccb_dm_cookie	cookie;
5268b8a9b1dSJustin T. Gibbs };
5278b8a9b1dSJustin T. Gibbs 
5288b8a9b1dSJustin T. Gibbs struct ccb_dev_match {
5298b8a9b1dSJustin T. Gibbs 	struct ccb_hdr			ccb_h;
5308b8a9b1dSJustin T. Gibbs 	ccb_dev_match_status		status;
5318b8a9b1dSJustin T. Gibbs 	u_int32_t			num_patterns;
5328b8a9b1dSJustin T. Gibbs 	u_int32_t			pattern_buf_len;
5338b8a9b1dSJustin T. Gibbs 	struct dev_match_pattern	*patterns;
5348b8a9b1dSJustin T. Gibbs 	u_int32_t			num_matches;
5358b8a9b1dSJustin T. Gibbs 	u_int32_t			match_buf_len;
5368b8a9b1dSJustin T. Gibbs 	struct dev_match_result		*matches;
5378b8a9b1dSJustin T. Gibbs 	struct ccb_dev_position		pos;
5388b8a9b1dSJustin T. Gibbs };
5398b8a9b1dSJustin T. Gibbs 
5408b8a9b1dSJustin T. Gibbs /*
5418b8a9b1dSJustin T. Gibbs  * Definitions for the path inquiry CCB fields.
5428b8a9b1dSJustin T. Gibbs  */
5431cc052e8SKenneth D. Merry #define CAM_VERSION	0x16	/* Hex value for current version */
5448b8a9b1dSJustin T. Gibbs 
5458b8a9b1dSJustin T. Gibbs typedef enum {
5468b8a9b1dSJustin T. Gibbs 	PI_MDP_ABLE	= 0x80,	/* Supports MDP message */
5478b8a9b1dSJustin T. Gibbs 	PI_WIDE_32	= 0x40,	/* Supports 32 bit wide SCSI */
5488b8a9b1dSJustin T. Gibbs 	PI_WIDE_16	= 0x20, /* Supports 16 bit wide SCSI */
5498b8a9b1dSJustin T. Gibbs 	PI_SDTR_ABLE	= 0x10,	/* Supports SDTR message */
5508b8a9b1dSJustin T. Gibbs 	PI_LINKED_CDB	= 0x08, /* Supports linked CDBs */
55152c9ce25SScott Long 	PI_SATAPM	= 0x04,	/* Supports SATA PM */
5528b8a9b1dSJustin T. Gibbs 	PI_TAG_ABLE	= 0x02,	/* Supports tag queue messages */
553273a1a3dSKenneth D. Merry 	PI_SOFT_RST	= 0x01	/* Supports soft reset alternative */
5548b8a9b1dSJustin T. Gibbs } pi_inqflag;
5558b8a9b1dSJustin T. Gibbs 
5568b8a9b1dSJustin T. Gibbs typedef enum {
5578b8a9b1dSJustin T. Gibbs 	PIT_PROCESSOR	= 0x80,	/* Target mode processor mode */
5588b8a9b1dSJustin T. Gibbs 	PIT_PHASE	= 0x40,	/* Target mode phase cog. mode */
5598b8a9b1dSJustin T. Gibbs 	PIT_DISCONNECT	= 0x20,	/* Disconnects supported in target mode */
5608b8a9b1dSJustin T. Gibbs 	PIT_TERM_IO	= 0x10,	/* Terminate I/O message supported in TM */
5618b8a9b1dSJustin T. Gibbs 	PIT_GRP_6	= 0x08,	/* Group 6 commands supported */
562273a1a3dSKenneth D. Merry 	PIT_GRP_7	= 0x04	/* Group 7 commands supported */
5638b8a9b1dSJustin T. Gibbs } pi_tmflag;
5648b8a9b1dSJustin T. Gibbs 
5658b8a9b1dSJustin T. Gibbs typedef enum {
5668b8a9b1dSJustin T. Gibbs 	PIM_SCANHILO	= 0x80,	/* Bus scans from high ID to low ID */
5678b8a9b1dSJustin T. Gibbs 	PIM_NOREMOVE	= 0x40,	/* Removeable devices not included in scan */
56898192658SJustin T. Gibbs 	PIM_NOINITIATOR	= 0x20,	/* Initiator role not supported. */
5691deac581SNate Lawson 	PIM_NOBUSRESET	= 0x10,	/* User has disabled initial BUS RESET */
570c1c3139eSMatt Jacob 	PIM_NO_6_BYTE	= 0x08,	/* Do not send 6-byte commands */
571c1c3139eSMatt Jacob 	PIM_SEQSCAN	= 0x04	/* Do bus scans sequentially, not in parallel */
5728b8a9b1dSJustin T. Gibbs } pi_miscflag;
5738b8a9b1dSJustin T. Gibbs 
5748b8a9b1dSJustin T. Gibbs /* Path Inquiry CCB */
5753393f8daSKenneth D. Merry struct ccb_pathinq_settings_spi {
5763393f8daSKenneth D. Merry 	u_int8_t ppr_options;
5773393f8daSKenneth D. Merry };
5782df76c16SMatt Jacob 
579fd13aa47SMatt Jacob struct ccb_pathinq_settings_fc {
580fd13aa47SMatt Jacob 	u_int64_t wwnn;		/* world wide node name */
581fd13aa47SMatt Jacob 	u_int64_t wwpn;		/* world wide port name */
582fd13aa47SMatt Jacob 	u_int32_t port;		/* 24 bit port id, if known */
583fd13aa47SMatt Jacob 	u_int32_t bitrate;	/* Mbps */
584fd13aa47SMatt Jacob };
5852df76c16SMatt Jacob 
586c4270cb6SMatt Jacob struct ccb_pathinq_settings_sas {
587c4270cb6SMatt Jacob 	u_int32_t bitrate;	/* Mbps */
588c4270cb6SMatt Jacob };
589fd13aa47SMatt Jacob #define	PATHINQ_SETTINGS_SIZE	128
5903393f8daSKenneth D. Merry 
5918b8a9b1dSJustin T. Gibbs struct ccb_pathinq {
5928b8a9b1dSJustin T. Gibbs 	struct 	    ccb_hdr ccb_h;
5938b8a9b1dSJustin T. Gibbs 	u_int8_t    version_num;	/* Version number for the SIM/HBA */
5948b8a9b1dSJustin T. Gibbs 	u_int8_t    hba_inquiry;	/* Mimic of INQ byte 7 for the HBA */
5958b8a9b1dSJustin T. Gibbs 	u_int8_t    target_sprt;	/* Flags for target mode support */
5968b8a9b1dSJustin T. Gibbs 	u_int8_t    hba_misc;		/* Misc HBA features */
5978b8a9b1dSJustin T. Gibbs 	u_int16_t   hba_eng_cnt;	/* HBA engine count */
5988b8a9b1dSJustin T. Gibbs 					/* Vendor Unique capabilities */
5998b8a9b1dSJustin T. Gibbs 	u_int8_t    vuhba_flags[VUHBALEN];
6008b8a9b1dSJustin T. Gibbs 	u_int32_t   max_target;		/* Maximum supported Target */
6018b8a9b1dSJustin T. Gibbs 	u_int32_t   max_lun;		/* Maximum supported Lun */
6028b8a9b1dSJustin T. Gibbs 	u_int32_t   async_flags;	/* Installed Async handlers */
6038b8a9b1dSJustin T. Gibbs 	path_id_t   hpath_id;		/* Highest Path ID in the subsystem */
6048b8a9b1dSJustin T. Gibbs 	target_id_t initiator_id;	/* ID of the HBA on the SCSI bus */
6058b8a9b1dSJustin T. Gibbs 	char	    sim_vid[SIM_IDLEN];	/* Vendor ID of the SIM */
6068b8a9b1dSJustin T. Gibbs 	char	    hba_vid[HBA_IDLEN];	/* Vendor ID of the HBA */
6078b8a9b1dSJustin T. Gibbs 	char 	    dev_name[DEV_IDLEN];/* Device name for SIM */
6088b8a9b1dSJustin T. Gibbs 	u_int32_t   unit_number;	/* Unit number for SIM */
6098b8a9b1dSJustin T. Gibbs 	u_int32_t   bus_id;		/* Bus ID for SIM */
6109deea857SKenneth D. Merry 	u_int32_t   base_transfer_speed;/* Base bus speed in KB/sec */
6113393f8daSKenneth D. Merry 	cam_proto   protocol;
6123393f8daSKenneth D. Merry 	u_int	    protocol_version;
6133393f8daSKenneth D. Merry 	cam_xport   transport;
6143393f8daSKenneth D. Merry 	u_int	    transport_version;
6153393f8daSKenneth D. Merry 	union {
6163393f8daSKenneth D. Merry 		struct ccb_pathinq_settings_spi spi;
617fd13aa47SMatt Jacob 		struct ccb_pathinq_settings_fc fc;
618c4270cb6SMatt Jacob 		struct ccb_pathinq_settings_sas sas;
619fd13aa47SMatt Jacob 		char ccb_pathinq_settings_opaque[PATHINQ_SETTINGS_SIZE];
6203393f8daSKenneth D. Merry 	} xport_specific;
62152c9ce25SScott Long 	u_int		maxio;		/* Max supported I/O size, in bytes. */
6228edcf694SAlexander Motin 	u_int16_t	hba_vendor;	/* HBA vendor ID */
6238edcf694SAlexander Motin 	u_int16_t	hba_device;	/* HBA device ID */
6248edcf694SAlexander Motin 	u_int16_t	hba_subvendor;	/* HBA subvendor ID */
6258edcf694SAlexander Motin 	u_int16_t	hba_subdevice;	/* HBA subdevice ID */
6268b8a9b1dSJustin T. Gibbs };
6278b8a9b1dSJustin T. Gibbs 
62887cfaf0eSJustin T. Gibbs /* Path Statistics CCB */
62987cfaf0eSJustin T. Gibbs struct ccb_pathstats {
63087cfaf0eSJustin T. Gibbs 	struct	ccb_hdr	ccb_h;
63187cfaf0eSJustin T. Gibbs 	struct	timeval last_reset;	/* Time of last bus reset/loop init */
63287cfaf0eSJustin T. Gibbs };
63387cfaf0eSJustin T. Gibbs 
63406e79492SKenneth D. Merry typedef enum {
63506e79492SKenneth D. Merry 	SMP_FLAG_NONE		= 0x00,
63606e79492SKenneth D. Merry 	SMP_FLAG_REQ_SG		= 0x01,
63706e79492SKenneth D. Merry 	SMP_FLAG_RSP_SG		= 0x02
63806e79492SKenneth D. Merry } ccb_smp_pass_flags;
63906e79492SKenneth D. Merry 
64006e79492SKenneth D. Merry /*
64106e79492SKenneth D. Merry  * Serial Management Protocol CCB
64206e79492SKenneth D. Merry  * XXX Currently the semantics for this CCB are that it is executed either
64306e79492SKenneth D. Merry  * by the addressed device, or that device's parent (i.e. an expander for
64406e79492SKenneth D. Merry  * any device on an expander) if the addressed device doesn't support SMP.
64506e79492SKenneth D. Merry  * Later, once we have the ability to probe SMP-only devices and put them
64606e79492SKenneth D. Merry  * in CAM's topology, the CCB will only be executed by the addressed device
64706e79492SKenneth D. Merry  * if possible.
64806e79492SKenneth D. Merry  */
64906e79492SKenneth D. Merry struct ccb_smpio {
65006e79492SKenneth D. Merry 	struct ccb_hdr		ccb_h;
65106e79492SKenneth D. Merry 	uint8_t			*smp_request;
65206e79492SKenneth D. Merry 	int			smp_request_len;
65306e79492SKenneth D. Merry 	uint16_t		smp_request_sglist_cnt;
65406e79492SKenneth D. Merry 	uint8_t			*smp_response;
65506e79492SKenneth D. Merry 	int			smp_response_len;
65606e79492SKenneth D. Merry 	uint16_t		smp_response_sglist_cnt;
65706e79492SKenneth D. Merry 	ccb_smp_pass_flags	flags;
65806e79492SKenneth D. Merry };
65906e79492SKenneth D. Merry 
6608b8a9b1dSJustin T. Gibbs typedef union {
6618b8a9b1dSJustin T. Gibbs 	u_int8_t *sense_ptr;		/*
6628b8a9b1dSJustin T. Gibbs 					 * Pointer to storage
6638b8a9b1dSJustin T. Gibbs 					 * for sense information
6648b8a9b1dSJustin T. Gibbs 					 */
6658b8a9b1dSJustin T. Gibbs 	                                /* Storage Area for sense information */
6668b8a9b1dSJustin T. Gibbs 	struct	 scsi_sense_data sense_buf;
6678b8a9b1dSJustin T. Gibbs } sense_t;
6688b8a9b1dSJustin T. Gibbs 
6698b8a9b1dSJustin T. Gibbs typedef union {
6708b8a9b1dSJustin T. Gibbs 	u_int8_t  *cdb_ptr;		/* Pointer to the CDB bytes to send */
6718b8a9b1dSJustin T. Gibbs 					/* Area for the CDB send */
6728b8a9b1dSJustin T. Gibbs 	u_int8_t  cdb_bytes[IOCDBLEN];
6738b8a9b1dSJustin T. Gibbs } cdb_t;
6748b8a9b1dSJustin T. Gibbs 
6758b8a9b1dSJustin T. Gibbs /*
6768b8a9b1dSJustin T. Gibbs  * SCSI I/O Request CCB used for the XPT_SCSI_IO and XPT_CONT_TARGET_IO
6778b8a9b1dSJustin T. Gibbs  * function codes.
6788b8a9b1dSJustin T. Gibbs  */
6798b8a9b1dSJustin T. Gibbs struct ccb_scsiio {
6808b8a9b1dSJustin T. Gibbs 	struct	   ccb_hdr ccb_h;
6818b8a9b1dSJustin T. Gibbs 	union	   ccb *next_ccb;	/* Ptr for next CCB for action */
6828b8a9b1dSJustin T. Gibbs 	u_int8_t   *req_map;		/* Ptr to mapping info */
6838b8a9b1dSJustin T. Gibbs 	u_int8_t   *data_ptr;		/* Ptr to the data buf/SG list */
6848b8a9b1dSJustin T. Gibbs 	u_int32_t  dxfer_len;		/* Data transfer length */
6858b8a9b1dSJustin T. Gibbs 					/* Autosense storage */
6868b8a9b1dSJustin T. Gibbs 	struct     scsi_sense_data sense_data;
6878b8a9b1dSJustin T. Gibbs 	u_int8_t   sense_len;		/* Number of bytes to autosense */
6888b8a9b1dSJustin T. Gibbs 	u_int8_t   cdb_len;		/* Number of bytes for the CDB */
6898b8a9b1dSJustin T. Gibbs 	u_int16_t  sglist_cnt;		/* Number of SG list entries */
6908b8a9b1dSJustin T. Gibbs 	u_int8_t   scsi_status;		/* Returned SCSI status */
6918b8a9b1dSJustin T. Gibbs 	u_int8_t   sense_resid;		/* Autosense resid length: 2's comp */
6928b8a9b1dSJustin T. Gibbs 	u_int32_t  resid;		/* Transfer residual length: 2's comp */
6938b8a9b1dSJustin T. Gibbs 	cdb_t	   cdb_io;		/* Union for CDB bytes/pointer */
6948b8a9b1dSJustin T. Gibbs 	u_int8_t   *msg_ptr;		/* Pointer to the message buffer */
6958b8a9b1dSJustin T. Gibbs 	u_int16_t  msg_len;		/* Number of bytes for the Message */
6968b8a9b1dSJustin T. Gibbs 	u_int8_t   tag_action;		/* What to do for tag queueing */
697bb1f2fe4SJustin T. Gibbs 	/*
698bb1f2fe4SJustin T. Gibbs 	 * The tag action should be either the define below (to send a
699bb1f2fe4SJustin T. Gibbs 	 * non-tagged transaction) or one of the defined scsi tag messages
700bb1f2fe4SJustin T. Gibbs 	 * from scsi_message.h.
701bb1f2fe4SJustin T. Gibbs 	 */
702bb1f2fe4SJustin T. Gibbs #define		CAM_TAG_ACTION_NONE	0x00
703bf8bb7acSJustin T. Gibbs 	u_int	   tag_id;		/* tag id from initator (target mode) */
704bf8bb7acSJustin T. Gibbs 	u_int	   init_id;		/* initiator id of who selected */
7058b8a9b1dSJustin T. Gibbs };
7068b8a9b1dSJustin T. Gibbs 
70752c9ce25SScott Long /*
70852c9ce25SScott Long  * ATA I/O Request CCB used for the XPT_ATA_IO function code.
70952c9ce25SScott Long  */
71052c9ce25SScott Long struct ccb_ataio {
71152c9ce25SScott Long 	struct	   ccb_hdr ccb_h;
71252c9ce25SScott Long 	union	   ccb *next_ccb;	/* Ptr for next CCB for action */
71352c9ce25SScott Long 	struct ata_cmd	cmd;		/* ATA command register set */
71452c9ce25SScott Long 	struct ata_res	res;		/* ATA result register set */
71552c9ce25SScott Long 	u_int8_t   *data_ptr;		/* Ptr to the data buf/SG list */
71652c9ce25SScott Long 	u_int32_t  dxfer_len;		/* Data transfer length */
71752c9ce25SScott Long 	u_int32_t  resid;		/* Transfer residual length: 2's comp */
71852c9ce25SScott Long 	u_int8_t   tag_action;		/* What to do for tag queueing */
71952c9ce25SScott Long 	/*
72052c9ce25SScott Long 	 * The tag action should be either the define below (to send a
72152c9ce25SScott Long 	 * non-tagged transaction) or one of the defined scsi tag messages
72252c9ce25SScott Long 	 * from scsi_message.h.
72352c9ce25SScott Long 	 */
72452c9ce25SScott Long #define		CAM_TAG_ACTION_NONE	0x00
72552c9ce25SScott Long 	u_int	   tag_id;		/* tag id from initator (target mode) */
72652c9ce25SScott Long 	u_int	   init_id;		/* initiator id of who selected */
72752c9ce25SScott Long };
72852c9ce25SScott Long 
7298b8a9b1dSJustin T. Gibbs struct ccb_accept_tio {
7308b8a9b1dSJustin T. Gibbs 	struct	   ccb_hdr ccb_h;
7318b8a9b1dSJustin T. Gibbs 	cdb_t	   cdb_io;		/* Union for CDB bytes/pointer */
7328b8a9b1dSJustin T. Gibbs 	u_int8_t   cdb_len;		/* Number of bytes for the CDB */
7338b8a9b1dSJustin T. Gibbs 	u_int8_t   tag_action;		/* What to do for tag queueing */
734826eb7c8SMatt Jacob 	u_int8_t   sense_len;		/* Number of bytes of Sense Data */
7352759b3c7SMatt Jacob 	u_int      tag_id;		/* tag id from initator (target mode) */
7362759b3c7SMatt Jacob 	u_int      init_id;		/* initiator id of who selected */
737826eb7c8SMatt Jacob 	struct     scsi_sense_data sense_data;
7388b8a9b1dSJustin T. Gibbs };
7398b8a9b1dSJustin T. Gibbs 
7408b8a9b1dSJustin T. Gibbs /* Release SIM Queue */
7418b8a9b1dSJustin T. Gibbs struct ccb_relsim {
7428b8a9b1dSJustin T. Gibbs 	struct ccb_hdr ccb_h;
7438b8a9b1dSJustin T. Gibbs 	u_int32_t      release_flags;
7448b8a9b1dSJustin T. Gibbs #define RELSIM_ADJUST_OPENINGS		0x01
7458b8a9b1dSJustin T. Gibbs #define RELSIM_RELEASE_AFTER_TIMEOUT	0x02
7468b8a9b1dSJustin T. Gibbs #define RELSIM_RELEASE_AFTER_CMDCMPLT	0x04
7478b8a9b1dSJustin T. Gibbs #define RELSIM_RELEASE_AFTER_QEMPTY	0x08
74883c5d981SAlexander Motin #define RELSIM_RELEASE_RUNLEVEL		0x10
7498b8a9b1dSJustin T. Gibbs 	u_int32_t      openings;
75083c5d981SAlexander Motin 	u_int32_t      release_timeout;	/* Abstract argument. */
7518b8a9b1dSJustin T. Gibbs 	u_int32_t      qfrozen_cnt;
7528b8a9b1dSJustin T. Gibbs };
7538b8a9b1dSJustin T. Gibbs 
7548b8a9b1dSJustin T. Gibbs /*
7558b8a9b1dSJustin T. Gibbs  * Definitions for the asynchronous callback CCB fields.
7568b8a9b1dSJustin T. Gibbs  */
7578b8a9b1dSJustin T. Gibbs typedef enum {
758*3631c638SAlexander Motin 	AC_UNIT_ATTENTION	= 0x4000,/* Device reported UNIT ATTENTION */
7593501942bSJustin T. Gibbs 	AC_ADVINFO_CHANGED	= 0x2000,/* Advance info might have changes */
7602df76c16SMatt Jacob 	AC_CONTRACT		= 0x1000,/* A contractual callback */
7618b8a9b1dSJustin T. Gibbs 	AC_GETDEV_CHANGED	= 0x800,/* Getdev info might have changed */
7628b8a9b1dSJustin T. Gibbs 	AC_INQ_CHANGED		= 0x400,/* Inquiry info might have changed */
7638b8a9b1dSJustin T. Gibbs 	AC_TRANSFER_NEG		= 0x200,/* New transfer settings in effect */
7648b8a9b1dSJustin T. Gibbs 	AC_LOST_DEVICE		= 0x100,/* A device went away */
7658b8a9b1dSJustin T. Gibbs 	AC_FOUND_DEVICE		= 0x080,/* A new device was found */
7668b8a9b1dSJustin T. Gibbs 	AC_PATH_DEREGISTERED	= 0x040,/* A path has de-registered */
7678b8a9b1dSJustin T. Gibbs 	AC_PATH_REGISTERED	= 0x020,/* A new path has been registered */
7688b8a9b1dSJustin T. Gibbs 	AC_SENT_BDR		= 0x010,/* A BDR message was sent to target */
7698b8a9b1dSJustin T. Gibbs 	AC_SCSI_AEN		= 0x008,/* A SCSI AEN has been received */
7708b8a9b1dSJustin T. Gibbs 	AC_UNSOL_RESEL		= 0x002,/* Unsolicited reselection occurred */
7718b8a9b1dSJustin T. Gibbs 	AC_BUS_RESET		= 0x001	/* A SCSI bus reset occurred */
7728b8a9b1dSJustin T. Gibbs } ac_code;
7738b8a9b1dSJustin T. Gibbs 
7748b8a9b1dSJustin T. Gibbs typedef void ac_callback_t (void *softc, u_int32_t code,
7758b8a9b1dSJustin T. Gibbs 			    struct cam_path *path, void *args);
7768b8a9b1dSJustin T. Gibbs 
7772df76c16SMatt Jacob /*
7782df76c16SMatt Jacob  * Generic Asynchronous callbacks.
7792df76c16SMatt Jacob  *
7802df76c16SMatt Jacob  * Generic arguments passed bac which are then interpreted between a per-system
7812df76c16SMatt Jacob  * contract number.
7822df76c16SMatt Jacob  */
7832df76c16SMatt Jacob #define	AC_CONTRACT_DATA_MAX (128 - sizeof (u_int64_t))
7842df76c16SMatt Jacob struct ac_contract {
7852df76c16SMatt Jacob 	u_int64_t	contract_number;
7862df76c16SMatt Jacob 	u_int8_t	contract_data[AC_CONTRACT_DATA_MAX];
7872df76c16SMatt Jacob };
7882df76c16SMatt Jacob 
7892df76c16SMatt Jacob #define	AC_CONTRACT_DEV_CHG	1
7902df76c16SMatt Jacob struct ac_device_changed {
7912df76c16SMatt Jacob 	u_int64_t	wwpn;
7922df76c16SMatt Jacob 	u_int32_t	port;
7932df76c16SMatt Jacob 	target_id_t	target;
7942df76c16SMatt Jacob 	u_int8_t	arrived;
7952df76c16SMatt Jacob };
7962df76c16SMatt Jacob 
7978b8a9b1dSJustin T. Gibbs /* Set Asynchronous Callback CCB */
7988b8a9b1dSJustin T. Gibbs struct ccb_setasync {
7998b8a9b1dSJustin T. Gibbs 	struct ccb_hdr	 ccb_h;
8008b8a9b1dSJustin T. Gibbs 	u_int32_t	 event_enable;	/* Async Event enables */
8018b8a9b1dSJustin T. Gibbs 	ac_callback_t	*callback;
8028b8a9b1dSJustin T. Gibbs 	void		*callback_arg;
8038b8a9b1dSJustin T. Gibbs };
8048b8a9b1dSJustin T. Gibbs 
8058b8a9b1dSJustin T. Gibbs /* Set Device Type CCB */
8068b8a9b1dSJustin T. Gibbs struct ccb_setdev {
8078b8a9b1dSJustin T. Gibbs 	struct	   ccb_hdr ccb_h;
8088b8a9b1dSJustin T. Gibbs 	u_int8_t   dev_type;	/* Value for dev type field in EDT */
8098b8a9b1dSJustin T. Gibbs };
8108b8a9b1dSJustin T. Gibbs 
8118b8a9b1dSJustin T. Gibbs /* SCSI Control Functions */
8128b8a9b1dSJustin T. Gibbs 
8138b8a9b1dSJustin T. Gibbs /* Abort XPT request CCB */
8148b8a9b1dSJustin T. Gibbs struct ccb_abort {
8158b8a9b1dSJustin T. Gibbs 	struct 	ccb_hdr ccb_h;
8168b8a9b1dSJustin T. Gibbs 	union	ccb *abort_ccb;	/* Pointer to CCB to abort */
8178b8a9b1dSJustin T. Gibbs };
8188b8a9b1dSJustin T. Gibbs 
8198b8a9b1dSJustin T. Gibbs /* Reset SCSI Bus CCB */
8208b8a9b1dSJustin T. Gibbs struct ccb_resetbus {
8218b8a9b1dSJustin T. Gibbs 	struct	ccb_hdr ccb_h;
8228b8a9b1dSJustin T. Gibbs };
8238b8a9b1dSJustin T. Gibbs 
8248b8a9b1dSJustin T. Gibbs /* Reset SCSI Device CCB */
8258b8a9b1dSJustin T. Gibbs struct ccb_resetdev {
8268b8a9b1dSJustin T. Gibbs 	struct	ccb_hdr ccb_h;
8278b8a9b1dSJustin T. Gibbs };
8288b8a9b1dSJustin T. Gibbs 
8298b8a9b1dSJustin T. Gibbs /* Terminate I/O Process Request CCB */
8308b8a9b1dSJustin T. Gibbs struct ccb_termio {
8318b8a9b1dSJustin T. Gibbs 	struct	ccb_hdr ccb_h;
8328b8a9b1dSJustin T. Gibbs 	union	ccb *termio_ccb;	/* Pointer to CCB to terminate */
8338b8a9b1dSJustin T. Gibbs };
8348b8a9b1dSJustin T. Gibbs 
8353393f8daSKenneth D. Merry typedef enum {
8363393f8daSKenneth D. Merry 	CTS_TYPE_CURRENT_SETTINGS,
8373393f8daSKenneth D. Merry 	CTS_TYPE_USER_SETTINGS
8383393f8daSKenneth D. Merry } cts_type;
8393393f8daSKenneth D. Merry 
8403393f8daSKenneth D. Merry struct ccb_trans_settings_scsi
8413393f8daSKenneth D. Merry {
8423393f8daSKenneth D. Merry 	u_int	valid;	/* Which fields to honor */
8433393f8daSKenneth D. Merry #define	CTS_SCSI_VALID_TQ		0x01
8443393f8daSKenneth D. Merry 	u_int	flags;
8453393f8daSKenneth D. Merry #define	CTS_SCSI_FLAGS_TAG_ENB		0x01
8463393f8daSKenneth D. Merry };
8473393f8daSKenneth D. Merry 
848b9c473b2SAlexander Motin struct ccb_trans_settings_ata
849b9c473b2SAlexander Motin {
850b9c473b2SAlexander Motin 	u_int	valid;	/* Which fields to honor */
851b9c473b2SAlexander Motin #define	CTS_ATA_VALID_TQ		0x01
852b9c473b2SAlexander Motin 	u_int	flags;
853b9c473b2SAlexander Motin #define	CTS_ATA_FLAGS_TAG_ENB		0x01
854b9c473b2SAlexander Motin };
855b9c473b2SAlexander Motin 
8563393f8daSKenneth D. Merry struct ccb_trans_settings_spi
8573393f8daSKenneth D. Merry {
8583393f8daSKenneth D. Merry 	u_int	  valid;	/* Which fields to honor */
8593393f8daSKenneth D. Merry #define	CTS_SPI_VALID_SYNC_RATE		0x01
8603393f8daSKenneth D. Merry #define	CTS_SPI_VALID_SYNC_OFFSET	0x02
8613393f8daSKenneth D. Merry #define	CTS_SPI_VALID_BUS_WIDTH		0x04
8623393f8daSKenneth D. Merry #define	CTS_SPI_VALID_DISC		0x08
8633393f8daSKenneth D. Merry #define CTS_SPI_VALID_PPR_OPTIONS	0x10
8643393f8daSKenneth D. Merry 	u_int	flags;
8653393f8daSKenneth D. Merry #define	CTS_SPI_FLAGS_DISC_ENB		0x01
8663393f8daSKenneth D. Merry 	u_int	sync_period;
8673393f8daSKenneth D. Merry 	u_int	sync_offset;
8683393f8daSKenneth D. Merry 	u_int	bus_width;
8693393f8daSKenneth D. Merry 	u_int	ppr_options;
8703393f8daSKenneth D. Merry };
8713393f8daSKenneth D. Merry 
872c1c84cd9SMatt Jacob struct ccb_trans_settings_fc {
873c1c84cd9SMatt Jacob 	u_int     	valid;		/* Which fields to honor */
874c1c84cd9SMatt Jacob #define	CTS_FC_VALID_WWNN		0x8000
875c1c84cd9SMatt Jacob #define	CTS_FC_VALID_WWPN		0x4000
876c1c84cd9SMatt Jacob #define	CTS_FC_VALID_PORT		0x2000
877c1c84cd9SMatt Jacob #define	CTS_FC_VALID_SPEED		0x1000
878c1c84cd9SMatt Jacob 	u_int64_t	wwnn;		/* world wide node name */
879c1c84cd9SMatt Jacob 	u_int64_t 	wwpn;		/* world wide port name */
880c1c84cd9SMatt Jacob 	u_int32_t 	port;		/* 24 bit port id, if known */
881c1c84cd9SMatt Jacob 	u_int32_t 	bitrate;	/* Mbps */
882c1c84cd9SMatt Jacob };
883c1c84cd9SMatt Jacob 
884c4270cb6SMatt Jacob struct ccb_trans_settings_sas {
885c4270cb6SMatt Jacob 	u_int     	valid;		/* Which fields to honor */
886c4270cb6SMatt Jacob #define	CTS_SAS_VALID_SPEED		0x1000
887c4270cb6SMatt Jacob 	u_int32_t 	bitrate;	/* Mbps */
888c4270cb6SMatt Jacob };
889c4270cb6SMatt Jacob 
890b9c473b2SAlexander Motin struct ccb_trans_settings_pata {
8911e637ba6SAlexander Motin 	u_int     	valid;		/* Which fields to honor */
8921e637ba6SAlexander Motin #define	CTS_ATA_VALID_MODE		0x01
893c8039fc6SAlexander Motin #define	CTS_ATA_VALID_BYTECOUNT		0x02
8944cca1530SAlexander Motin #define	CTS_ATA_VALID_ATAPI		0x20
895c8039fc6SAlexander Motin 	int		mode;		/* Mode */
8961e637ba6SAlexander Motin 	u_int 		bytecount;	/* Length of PIO transaction */
8974cca1530SAlexander Motin 	u_int 		atapi;		/* Length of ATAPI CDB */
8981e637ba6SAlexander Motin };
8991e637ba6SAlexander Motin 
90052c9ce25SScott Long struct ccb_trans_settings_sata {
90152c9ce25SScott Long 	u_int     	valid;		/* Which fields to honor */
902c8039fc6SAlexander Motin #define	CTS_SATA_VALID_MODE		0x01
903c8039fc6SAlexander Motin #define	CTS_SATA_VALID_BYTECOUNT	0x02
904c8039fc6SAlexander Motin #define	CTS_SATA_VALID_REVISION		0x04
905c8039fc6SAlexander Motin #define	CTS_SATA_VALID_PM		0x08
906c8039fc6SAlexander Motin #define	CTS_SATA_VALID_TAGS		0x10
9074cca1530SAlexander Motin #define	CTS_SATA_VALID_ATAPI		0x20
908da6808c1SAlexander Motin #define	CTS_SATA_VALID_CAPS		0x40
909c8039fc6SAlexander Motin 	int		mode;		/* Legacy PATA mode */
9101e637ba6SAlexander Motin 	u_int 		bytecount;	/* Length of PIO transaction */
911b447e682SAlexander Motin 	int		revision;	/* SATA revision */
912c8039fc6SAlexander Motin 	u_int 		pm_present;	/* PM is present (XPT->SIM) */
913c8039fc6SAlexander Motin 	u_int 		tags;		/* Number of allowed tags */
9144cca1530SAlexander Motin 	u_int 		atapi;		/* Length of ATAPI CDB */
915da6808c1SAlexander Motin 	u_int 		caps;		/* Device and host SATA caps. */
916da6808c1SAlexander Motin #define	CTS_SATA_CAPS_H			0x0000ffff
917da6808c1SAlexander Motin #define	CTS_SATA_CAPS_H_PMREQ		0x00000001
918da6808c1SAlexander Motin #define	CTS_SATA_CAPS_H_APST		0x00000002
919da6808c1SAlexander Motin #define	CTS_SATA_CAPS_H_DMAAA		0x00000010 /* Auto-activation */
9208d169381SAlexander Motin #define	CTS_SATA_CAPS_H_AN		0x00000020 /* Async. notification */
921da6808c1SAlexander Motin #define	CTS_SATA_CAPS_D			0xffff0000
922da6808c1SAlexander Motin #define	CTS_SATA_CAPS_D_PMREQ		0x00010000
923da6808c1SAlexander Motin #define	CTS_SATA_CAPS_D_APST		0x00020000
92452c9ce25SScott Long };
925c4270cb6SMatt Jacob 
9263393f8daSKenneth D. Merry /* Get/Set transfer rate/width/disconnection/tag queueing settings */
9273393f8daSKenneth D. Merry struct ccb_trans_settings {
9283393f8daSKenneth D. Merry 	struct	  ccb_hdr ccb_h;
9293393f8daSKenneth D. Merry 	cts_type  type;		/* Current or User settings */
9303393f8daSKenneth D. Merry 	cam_proto protocol;
9313393f8daSKenneth D. Merry 	u_int	  protocol_version;
9323393f8daSKenneth D. Merry 	cam_xport transport;
9333393f8daSKenneth D. Merry 	u_int	  transport_version;
9343393f8daSKenneth D. Merry 	union {
9353393f8daSKenneth D. Merry 		u_int  valid;	/* Which fields to honor */
936b9c473b2SAlexander Motin 		struct ccb_trans_settings_ata ata;
9373393f8daSKenneth D. Merry 		struct ccb_trans_settings_scsi scsi;
9383393f8daSKenneth D. Merry 	} proto_specific;
9393393f8daSKenneth D. Merry 	union {
9403393f8daSKenneth D. Merry 		u_int  valid;	/* Which fields to honor */
9413393f8daSKenneth D. Merry 		struct ccb_trans_settings_spi spi;
942c1c84cd9SMatt Jacob 		struct ccb_trans_settings_fc fc;
943c4270cb6SMatt Jacob 		struct ccb_trans_settings_sas sas;
944b9c473b2SAlexander Motin 		struct ccb_trans_settings_pata ata;
94552c9ce25SScott Long 		struct ccb_trans_settings_sata sata;
9463393f8daSKenneth D. Merry 	} xport_specific;
9473393f8daSKenneth D. Merry };
9483393f8daSKenneth D. Merry 
9493393f8daSKenneth D. Merry 
9508b8a9b1dSJustin T. Gibbs /*
9518b8a9b1dSJustin T. Gibbs  * Calculate the geometry parameters for a device
9528b8a9b1dSJustin T. Gibbs  * give the block size and volume size in blocks.
9538b8a9b1dSJustin T. Gibbs  */
9548b8a9b1dSJustin T. Gibbs struct ccb_calc_geometry {
9558b8a9b1dSJustin T. Gibbs 	struct	  ccb_hdr ccb_h;
9568b8a9b1dSJustin T. Gibbs 	u_int32_t block_size;
957260cc483SKenneth D. Merry 	u_int64_t volume_size;
958260cc483SKenneth D. Merry 	u_int32_t cylinders;
9598b8a9b1dSJustin T. Gibbs 	u_int8_t  heads;
9608b8a9b1dSJustin T. Gibbs 	u_int8_t  secs_per_track;
9618b8a9b1dSJustin T. Gibbs };
9628b8a9b1dSJustin T. Gibbs 
9638b8a9b1dSJustin T. Gibbs /*
9642df76c16SMatt Jacob  * Set or get SIM (and transport) specific knobs
9652df76c16SMatt Jacob  */
9662df76c16SMatt Jacob 
9672df76c16SMatt Jacob #define	KNOB_VALID_ADDRESS	0x1
9682df76c16SMatt Jacob #define	KNOB_VALID_ROLE		0x2
9692df76c16SMatt Jacob 
9702df76c16SMatt Jacob 
9712df76c16SMatt Jacob #define	KNOB_ROLE_NONE		0x0
9722df76c16SMatt Jacob #define	KNOB_ROLE_INITIATOR	0x1
9732df76c16SMatt Jacob #define	KNOB_ROLE_TARGET	0x2
9742df76c16SMatt Jacob #define	KNOB_ROLE_BOTH		0x3
9752df76c16SMatt Jacob 
9762df76c16SMatt Jacob struct ccb_sim_knob_settings_spi {
9772df76c16SMatt Jacob 	u_int		valid;
9782df76c16SMatt Jacob 	u_int		initiator_id;
9792df76c16SMatt Jacob 	u_int		role;
9802df76c16SMatt Jacob };
9812df76c16SMatt Jacob 
9822df76c16SMatt Jacob struct ccb_sim_knob_settings_fc {
9832df76c16SMatt Jacob 	u_int		valid;
9842df76c16SMatt Jacob 	u_int64_t	wwnn;		/* world wide node name */
9852df76c16SMatt Jacob 	u_int64_t 	wwpn;		/* world wide port name */
9862df76c16SMatt Jacob 	u_int		role;
9872df76c16SMatt Jacob };
9882df76c16SMatt Jacob 
9892df76c16SMatt Jacob struct ccb_sim_knob_settings_sas {
9902df76c16SMatt Jacob 	u_int		valid;
9912df76c16SMatt Jacob 	u_int64_t	wwnn;		/* world wide node name */
9922df76c16SMatt Jacob 	u_int		role;
9932df76c16SMatt Jacob };
9942df76c16SMatt Jacob #define	KNOB_SETTINGS_SIZE	128
9952df76c16SMatt Jacob 
9962df76c16SMatt Jacob struct ccb_sim_knob {
9972df76c16SMatt Jacob 	struct	  ccb_hdr ccb_h;
9982df76c16SMatt Jacob 	union {
9992df76c16SMatt Jacob 		u_int  valid;	/* Which fields to honor */
10002df76c16SMatt Jacob 		struct ccb_sim_knob_settings_spi spi;
10012df76c16SMatt Jacob 		struct ccb_sim_knob_settings_fc fc;
10022df76c16SMatt Jacob 		struct ccb_sim_knob_settings_sas sas;
10032df76c16SMatt Jacob 		char pad[KNOB_SETTINGS_SIZE];
10042df76c16SMatt Jacob 	} xport_specific;
10052df76c16SMatt Jacob };
10062df76c16SMatt Jacob 
10072df76c16SMatt Jacob /*
10088b8a9b1dSJustin T. Gibbs  * Rescan the given bus, or bus/target/lun
10098b8a9b1dSJustin T. Gibbs  */
10108b8a9b1dSJustin T. Gibbs struct ccb_rescan {
10118b8a9b1dSJustin T. Gibbs 	struct	ccb_hdr ccb_h;
10128b8a9b1dSJustin T. Gibbs 	cam_flags	flags;
10138b8a9b1dSJustin T. Gibbs };
10148b8a9b1dSJustin T. Gibbs 
10158b8a9b1dSJustin T. Gibbs /*
10168b8a9b1dSJustin T. Gibbs  * Turn on debugging for the given bus, bus/target, or bus/target/lun.
10178b8a9b1dSJustin T. Gibbs  */
10188b8a9b1dSJustin T. Gibbs struct ccb_debug {
10198b8a9b1dSJustin T. Gibbs 	struct	ccb_hdr ccb_h;
10208b8a9b1dSJustin T. Gibbs 	cam_debug_flags flags;
10218b8a9b1dSJustin T. Gibbs };
10228b8a9b1dSJustin T. Gibbs 
10238b8a9b1dSJustin T. Gibbs /* Target mode structures. */
10248b8a9b1dSJustin T. Gibbs 
10258b8a9b1dSJustin T. Gibbs struct ccb_en_lun {
10268b8a9b1dSJustin T. Gibbs 	struct	  ccb_hdr ccb_h;
10278b8a9b1dSJustin T. Gibbs 	u_int16_t grp6_len;		/* Group 6 VU CDB length */
10288b8a9b1dSJustin T. Gibbs 	u_int16_t grp7_len;		/* Group 7 VU CDB length */
10298b8a9b1dSJustin T. Gibbs 	u_int8_t  enable;
10308b8a9b1dSJustin T. Gibbs };
10318b8a9b1dSJustin T. Gibbs 
10322df76c16SMatt Jacob /* old, barely used immediate notify, binary compatibility */
10338b8a9b1dSJustin T. Gibbs struct ccb_immed_notify {
10348b8a9b1dSJustin T. Gibbs 	struct	  ccb_hdr ccb_h;
10358b8a9b1dSJustin T. Gibbs 	struct    scsi_sense_data sense_data;
1036826eb7c8SMatt Jacob 	u_int8_t  sense_len;		/* Number of bytes in sense buffer */
10378b8a9b1dSJustin T. Gibbs 	u_int8_t  initiator_id;		/* Id of initiator that selected */
10388b8a9b1dSJustin T. Gibbs 	u_int8_t  message_args[7];	/* Message Arguments */
10398b8a9b1dSJustin T. Gibbs };
10408b8a9b1dSJustin T. Gibbs 
10418b8a9b1dSJustin T. Gibbs struct ccb_notify_ack {
10428b8a9b1dSJustin T. Gibbs 	struct	  ccb_hdr ccb_h;
10438b8a9b1dSJustin T. Gibbs 	u_int16_t seq_id;		/* Sequence identifier */
10448b8a9b1dSJustin T. Gibbs 	u_int8_t  event;		/* Event flags */
10458b8a9b1dSJustin T. Gibbs };
10468b8a9b1dSJustin T. Gibbs 
10472df76c16SMatt Jacob struct ccb_immediate_notify {
10482df76c16SMatt Jacob 	struct    ccb_hdr ccb_h;
10492df76c16SMatt Jacob 	u_int     tag_id;		/* Tag for immediate notify */
10502df76c16SMatt Jacob 	u_int     seq_id;		/* Tag for target of notify */
10512df76c16SMatt Jacob 	u_int     initiator_id;		/* Initiator Identifier */
10522df76c16SMatt Jacob 	u_int     arg;			/* Function specific */
10532df76c16SMatt Jacob };
10542df76c16SMatt Jacob 
10552df76c16SMatt Jacob struct ccb_notify_acknowledge {
10562df76c16SMatt Jacob 	struct    ccb_hdr ccb_h;
10572df76c16SMatt Jacob 	u_int     tag_id;		/* Tag for immediate notify */
10582df76c16SMatt Jacob 	u_int     seq_id;		/* Tar for target of notify */
10592df76c16SMatt Jacob 	u_int     initiator_id;		/* Initiator Identifier */
10602df76c16SMatt Jacob 	u_int     arg;			/* Function specific */
10612df76c16SMatt Jacob };
10622df76c16SMatt Jacob 
10638b8a9b1dSJustin T. Gibbs /* HBA engine structures. */
10648b8a9b1dSJustin T. Gibbs 
10658b8a9b1dSJustin T. Gibbs typedef enum {
10668b8a9b1dSJustin T. Gibbs 	EIT_BUFFER,	/* Engine type: buffer memory */
10678b8a9b1dSJustin T. Gibbs 	EIT_LOSSLESS,	/* Engine type: lossless compression */
10688b8a9b1dSJustin T. Gibbs 	EIT_LOSSY,	/* Engine type: lossy compression */
10698b8a9b1dSJustin T. Gibbs 	EIT_ENCRYPT	/* Engine type: encryption */
10708b8a9b1dSJustin T. Gibbs } ei_type;
10718b8a9b1dSJustin T. Gibbs 
10728b8a9b1dSJustin T. Gibbs typedef enum {
10738b8a9b1dSJustin T. Gibbs 	EAD_VUNIQUE,	/* Engine algorithm ID: vendor unique */
10748b8a9b1dSJustin T. Gibbs 	EAD_LZ1V1,	/* Engine algorithm ID: LZ1 var.1 */
10758b8a9b1dSJustin T. Gibbs 	EAD_LZ2V1,	/* Engine algorithm ID: LZ2 var.1 */
1076273a1a3dSKenneth D. Merry 	EAD_LZ2V2	/* Engine algorithm ID: LZ2 var.2 */
10778b8a9b1dSJustin T. Gibbs } ei_algo;
10788b8a9b1dSJustin T. Gibbs 
10798b8a9b1dSJustin T. Gibbs struct ccb_eng_inq {
10808b8a9b1dSJustin T. Gibbs 	struct	  ccb_hdr ccb_h;
10818b8a9b1dSJustin T. Gibbs 	u_int16_t eng_num;	/* The engine number for this inquiry */
10828b8a9b1dSJustin T. Gibbs 	ei_type   eng_type;	/* Returned engine type */
10838b8a9b1dSJustin T. Gibbs 	ei_algo   eng_algo;	/* Returned engine algorithm type */
10848b8a9b1dSJustin T. Gibbs 	u_int32_t eng_memeory;	/* Returned engine memory size */
10858b8a9b1dSJustin T. Gibbs };
10868b8a9b1dSJustin T. Gibbs 
10878b8a9b1dSJustin T. Gibbs struct ccb_eng_exec {	/* This structure must match SCSIIO size */
10888b8a9b1dSJustin T. Gibbs 	struct	  ccb_hdr ccb_h;
10898b8a9b1dSJustin T. Gibbs 	u_int8_t  *pdrv_ptr;	/* Ptr used by the peripheral driver */
10908b8a9b1dSJustin T. Gibbs 	u_int8_t  *req_map;	/* Ptr for mapping info on the req. */
10918b8a9b1dSJustin T. Gibbs 	u_int8_t  *data_ptr;	/* Pointer to the data buf/SG list */
10928b8a9b1dSJustin T. Gibbs 	u_int32_t dxfer_len;	/* Data transfer length */
10938b8a9b1dSJustin T. Gibbs 	u_int8_t  *engdata_ptr;	/* Pointer to the engine buffer data */
10948b8a9b1dSJustin T. Gibbs 	u_int16_t sglist_cnt;	/* Num of scatter gather list entries */
10958b8a9b1dSJustin T. Gibbs 	u_int32_t dmax_len;	/* Destination data maximum length */
10968b8a9b1dSJustin T. Gibbs 	u_int32_t dest_len;	/* Destination data length */
10978b8a9b1dSJustin T. Gibbs 	int32_t	  src_resid;	/* Source residual length: 2's comp */
10988b8a9b1dSJustin T. Gibbs 	u_int32_t timeout;	/* Timeout value */
10998b8a9b1dSJustin T. Gibbs 	u_int16_t eng_num;	/* Engine number for this request */
11008b8a9b1dSJustin T. Gibbs 	u_int16_t vu_flags;	/* Vendor Unique flags */
11018b8a9b1dSJustin T. Gibbs };
11028b8a9b1dSJustin T. Gibbs 
11038b8a9b1dSJustin T. Gibbs /*
11048b8a9b1dSJustin T. Gibbs  * Definitions for the timeout field in the SCSI I/O CCB.
11058b8a9b1dSJustin T. Gibbs  */
11068b8a9b1dSJustin T. Gibbs #define	CAM_TIME_DEFAULT	0x00000000	/* Use SIM default value */
11078b8a9b1dSJustin T. Gibbs #define	CAM_TIME_INFINITY	0xFFFFFFFF	/* Infinite timeout */
11088b8a9b1dSJustin T. Gibbs 
11098b8a9b1dSJustin T. Gibbs #define	CAM_SUCCESS	0	/* For signaling general success */
11108b8a9b1dSJustin T. Gibbs #define	CAM_FAILURE	1	/* For signaling general failure */
11118b8a9b1dSJustin T. Gibbs 
11128b8a9b1dSJustin T. Gibbs #define CAM_FALSE	0
11138b8a9b1dSJustin T. Gibbs #define CAM_TRUE	1
11148b8a9b1dSJustin T. Gibbs 
11158b8a9b1dSJustin T. Gibbs #define XPT_CCB_INVALID	-1	/* for signaling a bad CCB to free */
11168b8a9b1dSJustin T. Gibbs 
11178b8a9b1dSJustin T. Gibbs /*
11183501942bSJustin T. Gibbs  * CCB for working with advanced device information.  This operates in a fashion
111906e79492SKenneth D. Merry  * similar to XPT_GDEV_TYPE.  Specify the target in ccb_h, the buffer
112006e79492SKenneth D. Merry  * type requested, and provide a buffer size/buffer to write to.  If the
11213501942bSJustin T. Gibbs  * buffer is too small, provsiz will be larger than bufsiz.
112206e79492SKenneth D. Merry  */
11233501942bSJustin T. Gibbs struct ccb_dev_advinfo {
112406e79492SKenneth D. Merry 	struct ccb_hdr ccb_h;
112506e79492SKenneth D. Merry 	uint32_t flags;
11263501942bSJustin T. Gibbs #define	CDAI_FLAG_STORE		0x1	/* If set, action becomes store */
112706e79492SKenneth D. Merry 	uint32_t buftype;		/* IN: Type of data being requested */
112806e79492SKenneth D. Merry 	/* NB: buftype is interpreted on a per-transport basis */
11293501942bSJustin T. Gibbs #define	CDAI_TYPE_SCSI_DEVID	1
11303501942bSJustin T. Gibbs #define	CDAI_TYPE_SERIAL_NUM	2
11313501942bSJustin T. Gibbs #define	CDAI_TYPE_PHYS_PATH	3
1132e6bd5983SKenneth D. Merry #define	CDAI_TYPE_RCAPLONG	4
113306e79492SKenneth D. Merry 	off_t bufsiz;			/* IN: Size of external buffer */
113406e79492SKenneth D. Merry #define	CAM_SCSI_DEVID_MAXLEN	65536	/* length in buffer is an uint16_t */
113506e79492SKenneth D. Merry 	off_t provsiz;			/* OUT: Size required/used */
113606e79492SKenneth D. Merry 	uint8_t *buf;			/* IN/OUT: Buffer for requested data */
113706e79492SKenneth D. Merry };
113806e79492SKenneth D. Merry 
113906e79492SKenneth D. Merry /*
11408b8a9b1dSJustin T. Gibbs  * Union of all CCB types for kernel space allocation.  This union should
11418b8a9b1dSJustin T. Gibbs  * never be used for manipulating CCBs - its only use is for the allocation
11428b8a9b1dSJustin T. Gibbs  * and deallocation of raw CCB space and is the return type of xpt_ccb_alloc
11438b8a9b1dSJustin T. Gibbs  * and the argument to xpt_ccb_free.
11448b8a9b1dSJustin T. Gibbs  */
11458b8a9b1dSJustin T. Gibbs union ccb {
11468b8a9b1dSJustin T. Gibbs 	struct	ccb_hdr			ccb_h;	/* For convenience */
11478b8a9b1dSJustin T. Gibbs 	struct	ccb_scsiio		csio;
11488b8a9b1dSJustin T. Gibbs 	struct	ccb_getdev		cgd;
11498b8a9b1dSJustin T. Gibbs 	struct	ccb_getdevlist		cgdl;
11508b8a9b1dSJustin T. Gibbs 	struct	ccb_pathinq		cpi;
11518b8a9b1dSJustin T. Gibbs 	struct	ccb_relsim		crs;
11528b8a9b1dSJustin T. Gibbs 	struct	ccb_setasync		csa;
11538b8a9b1dSJustin T. Gibbs 	struct	ccb_setdev		csd;
115487cfaf0eSJustin T. Gibbs 	struct	ccb_pathstats		cpis;
115587cfaf0eSJustin T. Gibbs 	struct	ccb_getdevstats		cgds;
11568b8a9b1dSJustin T. Gibbs 	struct	ccb_dev_match		cdm;
11578b8a9b1dSJustin T. Gibbs 	struct	ccb_trans_settings	cts;
11588b8a9b1dSJustin T. Gibbs 	struct	ccb_calc_geometry	ccg;
11592df76c16SMatt Jacob 	struct	ccb_sim_knob		knob;
11608b8a9b1dSJustin T. Gibbs 	struct	ccb_abort		cab;
11618b8a9b1dSJustin T. Gibbs 	struct	ccb_resetbus		crb;
11628b8a9b1dSJustin T. Gibbs 	struct	ccb_resetdev		crd;
11638b8a9b1dSJustin T. Gibbs 	struct	ccb_termio		tio;
11648b8a9b1dSJustin T. Gibbs 	struct	ccb_accept_tio		atio;
11658b8a9b1dSJustin T. Gibbs 	struct	ccb_scsiio		ctio;
11668b8a9b1dSJustin T. Gibbs 	struct	ccb_en_lun		cel;
11678b8a9b1dSJustin T. Gibbs 	struct	ccb_immed_notify	cin;
11688b8a9b1dSJustin T. Gibbs 	struct	ccb_notify_ack		cna;
11692df76c16SMatt Jacob 	struct	ccb_immediate_notify	cin1;
11702df76c16SMatt Jacob 	struct	ccb_notify_acknowledge	cna2;
11718b8a9b1dSJustin T. Gibbs 	struct	ccb_eng_inq		cei;
11728b8a9b1dSJustin T. Gibbs 	struct	ccb_eng_exec		cee;
117306e79492SKenneth D. Merry 	struct	ccb_smpio		smpio;
11748b8a9b1dSJustin T. Gibbs 	struct 	ccb_rescan		crcn;
11758b8a9b1dSJustin T. Gibbs 	struct  ccb_debug		cdbg;
117652c9ce25SScott Long 	struct	ccb_ataio		ataio;
11773501942bSJustin T. Gibbs 	struct	ccb_dev_advinfo		cdai;
11788b8a9b1dSJustin T. Gibbs };
11798b8a9b1dSJustin T. Gibbs 
11808b8a9b1dSJustin T. Gibbs __BEGIN_DECLS
11818b8a9b1dSJustin T. Gibbs static __inline void
11828b8a9b1dSJustin T. Gibbs cam_fill_csio(struct ccb_scsiio *csio, u_int32_t retries,
11838b8a9b1dSJustin T. Gibbs 	      void (*cbfcnp)(struct cam_periph *, union ccb *),
11848b8a9b1dSJustin T. Gibbs 	      u_int32_t flags, u_int8_t tag_action,
11858b8a9b1dSJustin T. Gibbs 	      u_int8_t *data_ptr, u_int32_t dxfer_len,
11868b8a9b1dSJustin T. Gibbs 	      u_int8_t sense_len, u_int8_t cdb_len,
11878b8a9b1dSJustin T. Gibbs 	      u_int32_t timeout);
11888b8a9b1dSJustin T. Gibbs 
11898b8a9b1dSJustin T. Gibbs static __inline void
11908b8a9b1dSJustin T. Gibbs cam_fill_ctio(struct ccb_scsiio *csio, u_int32_t retries,
11918b8a9b1dSJustin T. Gibbs 	      void (*cbfcnp)(struct cam_periph *, union ccb *),
11928b8a9b1dSJustin T. Gibbs 	      u_int32_t flags, u_int tag_action, u_int tag_id,
11938b8a9b1dSJustin T. Gibbs 	      u_int init_id, u_int scsi_status, u_int8_t *data_ptr,
11948b8a9b1dSJustin T. Gibbs 	      u_int32_t dxfer_len, u_int32_t timeout);
11958b8a9b1dSJustin T. Gibbs 
11968b8a9b1dSJustin T. Gibbs static __inline void
119752c9ce25SScott Long cam_fill_ataio(struct ccb_ataio *ataio, u_int32_t retries,
119852c9ce25SScott Long 	      void (*cbfcnp)(struct cam_periph *, union ccb *),
119952c9ce25SScott Long 	      u_int32_t flags, u_int tag_action,
120052c9ce25SScott Long 	      u_int8_t *data_ptr, u_int32_t dxfer_len,
120152c9ce25SScott Long 	      u_int32_t timeout);
120252c9ce25SScott Long 
120352c9ce25SScott Long static __inline void
120406e79492SKenneth D. Merry cam_fill_smpio(struct ccb_smpio *smpio, uint32_t retries,
120506e79492SKenneth D. Merry 	       void (*cbfcnp)(struct cam_periph *, union ccb *), uint32_t flags,
120606e79492SKenneth D. Merry 	       uint8_t *smp_request, int smp_request_len,
120706e79492SKenneth D. Merry 	       uint8_t *smp_response, int smp_response_len,
120806e79492SKenneth D. Merry 	       uint32_t timeout);
120906e79492SKenneth D. Merry 
121006e79492SKenneth D. Merry static __inline void
12118b8a9b1dSJustin T. Gibbs cam_fill_csio(struct ccb_scsiio *csio, u_int32_t retries,
12128b8a9b1dSJustin T. Gibbs 	      void (*cbfcnp)(struct cam_periph *, union ccb *),
12138b8a9b1dSJustin T. Gibbs 	      u_int32_t flags, u_int8_t tag_action,
12148b8a9b1dSJustin T. Gibbs 	      u_int8_t *data_ptr, u_int32_t dxfer_len,
12158b8a9b1dSJustin T. Gibbs 	      u_int8_t sense_len, u_int8_t cdb_len,
12168b8a9b1dSJustin T. Gibbs 	      u_int32_t timeout)
12178b8a9b1dSJustin T. Gibbs {
12188b8a9b1dSJustin T. Gibbs 	csio->ccb_h.func_code = XPT_SCSI_IO;
12198b8a9b1dSJustin T. Gibbs 	csio->ccb_h.flags = flags;
12208b8a9b1dSJustin T. Gibbs 	csio->ccb_h.retry_count = retries;
12218b8a9b1dSJustin T. Gibbs 	csio->ccb_h.cbfcnp = cbfcnp;
12228b8a9b1dSJustin T. Gibbs 	csio->ccb_h.timeout = timeout;
12238b8a9b1dSJustin T. Gibbs 	csio->data_ptr = data_ptr;
12248b8a9b1dSJustin T. Gibbs 	csio->dxfer_len = dxfer_len;
12258b8a9b1dSJustin T. Gibbs 	csio->sense_len = sense_len;
12268b8a9b1dSJustin T. Gibbs 	csio->cdb_len = cdb_len;
12278b8a9b1dSJustin T. Gibbs 	csio->tag_action = tag_action;
12288b8a9b1dSJustin T. Gibbs }
12298b8a9b1dSJustin T. Gibbs 
12308b8a9b1dSJustin T. Gibbs static __inline void
12318b8a9b1dSJustin T. Gibbs cam_fill_ctio(struct ccb_scsiio *csio, u_int32_t retries,
12328b8a9b1dSJustin T. Gibbs 	      void (*cbfcnp)(struct cam_periph *, union ccb *),
12338b8a9b1dSJustin T. Gibbs 	      u_int32_t flags, u_int tag_action, u_int tag_id,
12348b8a9b1dSJustin T. Gibbs 	      u_int init_id, u_int scsi_status, u_int8_t *data_ptr,
12358b8a9b1dSJustin T. Gibbs 	      u_int32_t dxfer_len, u_int32_t timeout)
12368b8a9b1dSJustin T. Gibbs {
12378b8a9b1dSJustin T. Gibbs 	csio->ccb_h.func_code = XPT_CONT_TARGET_IO;
12388b8a9b1dSJustin T. Gibbs 	csio->ccb_h.flags = flags;
12398b8a9b1dSJustin T. Gibbs 	csio->ccb_h.retry_count = retries;
12408b8a9b1dSJustin T. Gibbs 	csio->ccb_h.cbfcnp = cbfcnp;
12418b8a9b1dSJustin T. Gibbs 	csio->ccb_h.timeout = timeout;
12428b8a9b1dSJustin T. Gibbs 	csio->data_ptr = data_ptr;
12438b8a9b1dSJustin T. Gibbs 	csio->dxfer_len = dxfer_len;
12448b8a9b1dSJustin T. Gibbs 	csio->scsi_status = scsi_status;
12458b8a9b1dSJustin T. Gibbs 	csio->tag_action = tag_action;
12468b8a9b1dSJustin T. Gibbs 	csio->tag_id = tag_id;
12478b8a9b1dSJustin T. Gibbs 	csio->init_id = init_id;
12488b8a9b1dSJustin T. Gibbs }
12498b8a9b1dSJustin T. Gibbs 
125052c9ce25SScott Long static __inline void
125152c9ce25SScott Long cam_fill_ataio(struct ccb_ataio *ataio, u_int32_t retries,
125252c9ce25SScott Long 	      void (*cbfcnp)(struct cam_periph *, union ccb *),
125352c9ce25SScott Long 	      u_int32_t flags, u_int tag_action,
125452c9ce25SScott Long 	      u_int8_t *data_ptr, u_int32_t dxfer_len,
125552c9ce25SScott Long 	      u_int32_t timeout)
125652c9ce25SScott Long {
125752c9ce25SScott Long 	ataio->ccb_h.func_code = XPT_ATA_IO;
125852c9ce25SScott Long 	ataio->ccb_h.flags = flags;
125952c9ce25SScott Long 	ataio->ccb_h.retry_count = retries;
126052c9ce25SScott Long 	ataio->ccb_h.cbfcnp = cbfcnp;
126152c9ce25SScott Long 	ataio->ccb_h.timeout = timeout;
126252c9ce25SScott Long 	ataio->data_ptr = data_ptr;
126352c9ce25SScott Long 	ataio->dxfer_len = dxfer_len;
126452c9ce25SScott Long 	ataio->tag_action = tag_action;
126552c9ce25SScott Long }
126652c9ce25SScott Long 
126706e79492SKenneth D. Merry static __inline void
126806e79492SKenneth D. Merry cam_fill_smpio(struct ccb_smpio *smpio, uint32_t retries,
126906e79492SKenneth D. Merry 	       void (*cbfcnp)(struct cam_periph *, union ccb *), uint32_t flags,
127006e79492SKenneth D. Merry 	       uint8_t *smp_request, int smp_request_len,
127106e79492SKenneth D. Merry 	       uint8_t *smp_response, int smp_response_len,
127206e79492SKenneth D. Merry 	       uint32_t timeout)
127306e79492SKenneth D. Merry {
127406e79492SKenneth D. Merry #ifdef _KERNEL
127506e79492SKenneth D. Merry 	KASSERT((flags & CAM_DIR_MASK) == CAM_DIR_BOTH,
127606e79492SKenneth D. Merry 		("direction != CAM_DIR_BOTH"));
127706e79492SKenneth D. Merry 	KASSERT((smp_request != NULL) && (smp_response != NULL),
127806e79492SKenneth D. Merry 		("need valid request and response buffers"));
127906e79492SKenneth D. Merry 	KASSERT((smp_request_len != 0) && (smp_response_len != 0),
128006e79492SKenneth D. Merry 		("need non-zero request and response lengths"));
128106e79492SKenneth D. Merry #endif /*_KERNEL*/
128206e79492SKenneth D. Merry 	smpio->ccb_h.func_code = XPT_SMP_IO;
128306e79492SKenneth D. Merry 	smpio->ccb_h.flags = flags;
128406e79492SKenneth D. Merry 	smpio->ccb_h.retry_count = retries;
128506e79492SKenneth D. Merry 	smpio->ccb_h.cbfcnp = cbfcnp;
128606e79492SKenneth D. Merry 	smpio->ccb_h.timeout = timeout;
128706e79492SKenneth D. Merry 	smpio->smp_request = smp_request;
128806e79492SKenneth D. Merry 	smpio->smp_request_len = smp_request_len;
128906e79492SKenneth D. Merry 	smpio->smp_response = smp_response;
129006e79492SKenneth D. Merry 	smpio->smp_response_len = smp_response_len;
129106e79492SKenneth D. Merry }
129206e79492SKenneth D. Merry 
1293141bdcc1SNate Lawson void cam_calc_geometry(struct ccb_calc_geometry *ccg, int extended);
1294141bdcc1SNate Lawson 
12958b8a9b1dSJustin T. Gibbs __END_DECLS
12968b8a9b1dSJustin T. Gibbs 
12978b8a9b1dSJustin T. Gibbs #endif /* _CAM_CAM_CCB_H */
1298