1139743Simp/*-
239212Sgibbs * Data structures and definitions for CAM Control Blocks (CCBs).
339212Sgibbs *
439212Sgibbs * Copyright (c) 1997, 1998 Justin T. Gibbs.
539212Sgibbs * All rights reserved.
639212Sgibbs *
739212Sgibbs * Redistribution and use in source and binary forms, with or without
839212Sgibbs * modification, are permitted provided that the following conditions
939212Sgibbs * are met:
1039212Sgibbs * 1. Redistributions of source code must retain the above copyright
1139212Sgibbs *    notice, this list of conditions, and the following disclaimer,
1239212Sgibbs *    without modification, immediately at the beginning of the file.
1339212Sgibbs * 2. The name of the author may not be used to endorse or promote products
1439212Sgibbs *    derived from this software without specific prior written permission.
1539212Sgibbs *
1639212Sgibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1739212Sgibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1839212Sgibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1939212Sgibbs * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
2039212Sgibbs * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2139212Sgibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2239212Sgibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2339212Sgibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2439212Sgibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2539212Sgibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2639212Sgibbs * SUCH DAMAGE.
2739212Sgibbs *
2850477Speter * $FreeBSD$
2939212Sgibbs */
3039212Sgibbs
3139212Sgibbs#ifndef _CAM_CAM_CCB_H
3239212Sgibbs#define _CAM_CAM_CCB_H 1
3339212Sgibbs
3439212Sgibbs#include <sys/queue.h>
3539212Sgibbs#include <sys/cdefs.h>
3647412Sgibbs#include <sys/time.h>
37114216Skan#include <sys/limits.h>
3855206Speter#ifndef _KERNEL
3939212Sgibbs#include <sys/callout.h>
4039212Sgibbs#endif
4139212Sgibbs#include <cam/cam_debug.h>
4239212Sgibbs#include <cam/scsi/scsi_all.h>
43195534Sscottl#include <cam/ata/ata_all.h>
4439212Sgibbs
4539212Sgibbs/* General allocation length definitions for CCB structures */
4639212Sgibbs#define	IOCDBLEN	CAM_MAX_CDBLEN	/* Space for CDB bytes/pointer */
4739212Sgibbs#define	VUHBALEN	14		/* Vendor Unique HBA length */
4839212Sgibbs#define	SIM_IDLEN	16		/* ASCII string len for SIM ID */
4939212Sgibbs#define	HBA_IDLEN	16		/* ASCII string len for HBA ID */
5039212Sgibbs#define	DEV_IDLEN	16		/* ASCII string len for device names */
5139212Sgibbs#define CCB_PERIPH_PRIV_SIZE 	2	/* size of peripheral private area */
5239212Sgibbs#define CCB_SIM_PRIV_SIZE 	2	/* size of sim private area */
5339212Sgibbs
5439212Sgibbs/* Struct definitions for CAM control blocks */
5539212Sgibbs
5639212Sgibbs/* Common CCB header */
5739212Sgibbs/* CAM CCB flags */
5839212Sgibbstypedef enum {
5939212Sgibbs	CAM_CDB_POINTER		= 0x00000001,/* The CDB field is a pointer    */
6039212Sgibbs	CAM_QUEUE_ENABLE	= 0x00000002,/* SIM queue actions are enabled */
6139212Sgibbs	CAM_CDB_LINKED		= 0x00000004,/* CCB contains a linked CDB     */
6263455Sgibbs	CAM_NEGOTIATE		= 0x00000008,/*
6363455Sgibbs					      * Perform transport negotiation
6463455Sgibbs					      * with this command.
6563455Sgibbs					      */
66246713Skib	CAM_DATA_ISPHYS		= 0x00000010,/* Data type with physical addrs */
6739212Sgibbs	CAM_DIS_AUTOSENSE	= 0x00000020,/* Disable autosense feature     */
68216088Sken	CAM_DIR_BOTH		= 0x00000000,/* Data direction (00:IN/OUT)    */
6939212Sgibbs	CAM_DIR_IN		= 0x00000040,/* Data direction (01:DATA IN)   */
7039212Sgibbs	CAM_DIR_OUT		= 0x00000080,/* Data direction (10:DATA OUT)  */
7139212Sgibbs	CAM_DIR_NONE		= 0x000000C0,/* Data direction (11:no data)   */
7239212Sgibbs	CAM_DIR_MASK		= 0x000000C0,/* Data direction Mask	      */
73246713Skib	CAM_DATA_VADDR		= 0x00000000,/* Data type (000:Virtual)       */
74246713Skib	CAM_DATA_PADDR		= 0x00000010,/* Data type (001:Physical)      */
75246713Skib	CAM_DATA_SG		= 0x00040000,/* Data type (010:sglist)        */
76246713Skib	CAM_DATA_SG_PADDR	= 0x00040010,/* Data type (011:sglist phys)   */
77246713Skib	CAM_DATA_BIO		= 0x00200000,/* Data type (100:bio)           */
78246713Skib	CAM_DATA_MASK		= 0x00240010,/* Data type mask                */
7939212Sgibbs	CAM_SOFT_RST_OP		= 0x00000100,/* Use Soft reset alternative    */
8039212Sgibbs	CAM_ENG_SYNC		= 0x00000200,/* Flush resid bytes on complete */
8139212Sgibbs	CAM_DEV_QFRZDIS		= 0x00000400,/* Disable DEV Q freezing	      */
8239212Sgibbs	CAM_DEV_QFREEZE		= 0x00000800,/* Freeze DEV Q on execution     */
8339212Sgibbs	CAM_HIGH_POWER		= 0x00001000,/* Command takes a lot of power  */
8439212Sgibbs	CAM_SENSE_PTR		= 0x00002000,/* Sense data is a pointer	      */
8539212Sgibbs	CAM_SENSE_PHYS		= 0x00004000,/* Sense pointer is physical addr*/
8639212Sgibbs	CAM_TAG_ACTION_VALID	= 0x00008000,/* Use the tag action in this ccb*/
8739212Sgibbs	CAM_PASS_ERR_RECOVER	= 0x00010000,/* Pass driver does err. recovery*/
8839212Sgibbs	CAM_DIS_DISCONNECT	= 0x00020000,/* Disable disconnect	      */
8939212Sgibbs	CAM_MSG_BUF_PHYS	= 0x00080000,/* Message buffer ptr is physical*/
9039212Sgibbs	CAM_SNS_BUF_PHYS	= 0x00100000,/* Autosense data ptr is physical*/
9139212Sgibbs	CAM_CDB_PHYS		= 0x00400000,/* CDB poiner is physical	      */
9239212Sgibbs	CAM_ENG_SGLIST		= 0x00800000,/* SG list is for the HBA engine */
9339212Sgibbs
9439212Sgibbs/* Phase cognizant mode flags */
9558111Sn_hibma	CAM_DIS_AUTOSRP		= 0x01000000,/* Disable autosave/restore ptrs */
9639212Sgibbs	CAM_DIS_AUTODISC	= 0x02000000,/* Disable auto disconnect	      */
9739212Sgibbs	CAM_TGT_CCB_AVAIL	= 0x04000000,/* Target CCB available	      */
9839212Sgibbs	CAM_TGT_PHASE_MODE	= 0x08000000,/* The SIM runs in phase mode    */
9956145Smjacob	CAM_MSGB_VALID		= 0x10000000,/* Message buffer valid	      */
10056145Smjacob	CAM_STATUS_VALID	= 0x20000000,/* Status buffer valid	      */
10156145Smjacob	CAM_DATAB_VALID		= 0x40000000,/* Data buffer valid	      */
102248520Skib
10339212Sgibbs/* Host target Mode flags */
10456145Smjacob	CAM_SEND_SENSE		= 0x08000000,/* Send sense data with status   */
10556145Smjacob	CAM_TERM_IO		= 0x10000000,/* Terminate I/O Message sup.    */
10656145Smjacob	CAM_DISCONNECT		= 0x20000000,/* Disconnects are mandatory     */
107260387Sscottl	CAM_SEND_STATUS		= 0x40000000,/* Send status after data phase  */
108260387Sscottl
109260387Sscottl	CAM_UNLOCKED		= 0x80000000 /* Call callback without lock.   */
11039212Sgibbs} ccb_flags;
11139212Sgibbs
112255870Sscottltypedef enum {
113255870Sscottl	CAM_EXTLUN_VALID	= 0x00000001,/* 64bit lun field is valid      */
114255870Sscottl} ccb_xflags;
115255870Sscottl
11639212Sgibbs/* XPT Opcodes for xpt_action */
11739212Sgibbstypedef enum {
11846581Sken/* Function code flags are bits greater than 0xff */
11946581Sken	XPT_FC_QUEUED		= 0x100,
12046581Sken				/* Non-immediate function code */
12146581Sken	XPT_FC_USER_CCB		= 0x200,
12246581Sken	XPT_FC_XPT_ONLY		= 0x400,
12346581Sken				/* Only for the transport layer device */
12449925Sgibbs	XPT_FC_DEV_QUEUED	= 0x800 | XPT_FC_QUEUED,
12549925Sgibbs				/* Passes through the device queues */
12639212Sgibbs/* Common function commands: 0x00->0x0F */
12746581Sken	XPT_NOOP 		= 0x00,
12846581Sken				/* Execute Nothing */
12949925Sgibbs	XPT_SCSI_IO		= 0x01 | XPT_FC_DEV_QUEUED,
13046581Sken				/* Execute the requested I/O operation */
13146581Sken	XPT_GDEV_TYPE		= 0x02,
13246581Sken				/* Get type information for specified device */
13346581Sken	XPT_GDEVLIST		= 0x03,
13446581Sken				/* Get a list of peripheral devices */
13546581Sken	XPT_PATH_INQ		= 0x04,
13646581Sken				/* Path routing inquiry */
13746581Sken	XPT_REL_SIMQ		= 0x05,
138203108Smav				/* Release a frozen device queue */
13946581Sken	XPT_SASYNC_CB		= 0x06,
14046581Sken				/* Set Asynchronous Callback Parameters */
14146581Sken	XPT_SDEV_TYPE		= 0x07,
14246581Sken				/* Set device type information */
14346581Sken	XPT_SCAN_BUS		= 0x08 | XPT_FC_QUEUED | XPT_FC_USER_CCB
14446581Sken				       | XPT_FC_XPT_ONLY,
14546581Sken				/* (Re)Scan the SCSI Bus */
14646581Sken	XPT_DEV_MATCH		= 0x09 | XPT_FC_XPT_ONLY,
14746581Sken				/* Get EDT entries matching the given pattern */
14846581Sken	XPT_DEBUG		= 0x0a,
14946581Sken				/* Turn on debugging for a bus, target or lun */
15047412Sgibbs	XPT_PATH_STATS		= 0x0b,
15147412Sgibbs				/* Path statistics (error counts, etc.) */
15247412Sgibbs	XPT_GDEV_STATS		= 0x0c,
15347412Sgibbs				/* Device statistics (error counts, etc.) */
154223081Sgibbs	XPT_DEV_ADVINFO		= 0x0e,
155223081Sgibbs				/* Get/Set Device advanced information */
156260387Sscottl	XPT_ASYNC		= 0x0f | XPT_FC_QUEUED | XPT_FC_USER_CCB
157260387Sscottl				       | XPT_FC_XPT_ONLY,
158260387Sscottl				/* Asynchronous event */
15939212Sgibbs/* SCSI Control Functions: 0x10->0x1F */
16046581Sken	XPT_ABORT		= 0x10,
16146581Sken				/* Abort the specified CCB */
16246581Sken	XPT_RESET_BUS		= 0x11 | XPT_FC_XPT_ONLY,
16346581Sken				/* Reset the specified SCSI bus */
16449925Sgibbs	XPT_RESET_DEV		= 0x12 | XPT_FC_DEV_QUEUED,
16546581Sken				/* Bus Device Reset the specified SCSI device */
16646581Sken	XPT_TERM_IO		= 0x13,
16746581Sken				/* Terminate the I/O process */
16846581Sken	XPT_SCAN_LUN		= 0x14 | XPT_FC_QUEUED | XPT_FC_USER_CCB
16946581Sken				       | XPT_FC_XPT_ONLY,
17046581Sken				/* Scan Logical Unit */
17146581Sken	XPT_GET_TRAN_SETTINGS	= 0x15,
17246581Sken				/*
17339212Sgibbs				 * Get default/user transfer settings
17439212Sgibbs				 * for the target
17539212Sgibbs				 */
17646581Sken	XPT_SET_TRAN_SETTINGS	= 0x16,
17746581Sken				/*
17839212Sgibbs				 * Set transfer rate/width
17939212Sgibbs				 * negotiation settings
18039212Sgibbs				 */
18146581Sken	XPT_CALC_GEOMETRY	= 0x17,
18246581Sken				/*
18339212Sgibbs				 * Calculate the geometry parameters for
18439212Sgibbs				 * a device give the sector size and
18539212Sgibbs				 * volume size.
18639212Sgibbs				 */
187195534Sscottl	XPT_ATA_IO		= 0x18 | XPT_FC_DEV_QUEUED,
188195534Sscottl				/* Execute the requested ATA I/O operation */
18939212Sgibbs
190196008Smjacob	XPT_GET_SIM_KNOB	= 0x18,
191196008Smjacob				/*
192196008Smjacob				 * Get SIM specific knob values.
193196008Smjacob				 */
194196008Smjacob
195196008Smjacob	XPT_SET_SIM_KNOB	= 0x19,
196196008Smjacob				/*
197196008Smjacob				 * Set SIM specific knob values.
198196008Smjacob				 */
199208582Smjacob
200216088Sken	XPT_SMP_IO		= 0x1b | XPT_FC_DEV_QUEUED,
201216088Sken				/* Serial Management Protocol */
202216088Sken
203208582Smjacob	XPT_SCAN_TGT		= 0x1E | XPT_FC_QUEUED | XPT_FC_USER_CCB
204208582Smjacob				       | XPT_FC_XPT_ONLY,
205208582Smjacob				/* Scan Target */
206208582Smjacob
20739212Sgibbs/* HBA engine commands 0x20->0x2F */
20846581Sken	XPT_ENG_INQ		= 0x20 | XPT_FC_XPT_ONLY,
20946581Sken				/* HBA engine feature inquiry */
21074840Sken	XPT_ENG_EXEC		= 0x21 | XPT_FC_DEV_QUEUED,
21146581Sken				/* HBA execute engine request */
21239212Sgibbs
21339212Sgibbs/* Target mode commands: 0x30->0x3F */
21446581Sken	XPT_EN_LUN		= 0x30,
21546581Sken				/* Enable LUN as a target */
21649925Sgibbs	XPT_TARGET_IO		= 0x31 | XPT_FC_DEV_QUEUED,
21746581Sken				/* Execute target I/O request */
21846581Sken	XPT_ACCEPT_TARGET_IO	= 0x32 | XPT_FC_QUEUED | XPT_FC_USER_CCB,
21946581Sken				/* Accept Host Target Mode CDB */
22049925Sgibbs	XPT_CONT_TARGET_IO	= 0x33 | XPT_FC_DEV_QUEUED,
22146581Sken				/* Continue Host Target I/O Connection */
22246581Sken	XPT_IMMED_NOTIFY	= 0x34 | XPT_FC_QUEUED | XPT_FC_USER_CCB,
223196008Smjacob				/* Notify Host Target driver of event (obsolete) */
224196008Smjacob	XPT_NOTIFY_ACK		= 0x35,
225196008Smjacob				/* Acknowledgement of event (obsolete) */
226196008Smjacob	XPT_IMMEDIATE_NOTIFY	= 0x36 | XPT_FC_QUEUED | XPT_FC_USER_CCB,
22746581Sken				/* Notify Host Target driver of event */
228196008Smjacob	XPT_NOTIFY_ACKNOWLEDGE	= 0x37 | XPT_FC_QUEUED | XPT_FC_USER_CCB,
22946581Sken				/* Acknowledgement of event */
23039212Sgibbs
23139212Sgibbs/* Vendor Unique codes: 0x80->0x8F */
23246581Sken	XPT_VUNIQUE		= 0x80
23339212Sgibbs} xpt_opcode;
23439212Sgibbs
23546581Sken#define XPT_FC_GROUP_MASK		0xF0
23646581Sken#define XPT_FC_GROUP(op) ((op) & XPT_FC_GROUP_MASK)
23746581Sken#define XPT_FC_GROUP_COMMON		0x00
23846581Sken#define XPT_FC_GROUP_SCSI_CONTROL	0x10
23949925Sgibbs#define XPT_FC_GROUP_HBA_ENGINE		0x20
24046581Sken#define XPT_FC_GROUP_TMODE		0x30
24146581Sken#define XPT_FC_GROUP_VENDOR_UNIQUE	0x80
24244499Sgibbs
24349925Sgibbs#define XPT_FC_IS_DEV_QUEUED(ccb) 	\
24449925Sgibbs    (((ccb)->ccb_h.func_code & XPT_FC_DEV_QUEUED) == XPT_FC_DEV_QUEUED)
24549925Sgibbs#define XPT_FC_IS_QUEUED(ccb) 	\
24649925Sgibbs    (((ccb)->ccb_h.func_code & XPT_FC_QUEUED) != 0)
24774840Sken
24874840Skentypedef enum {
24974840Sken	PROTO_UNKNOWN,
25074840Sken	PROTO_UNSPECIFIED,
25174840Sken	PROTO_SCSI,	/* Small Computer System Interface */
25274840Sken	PROTO_ATA,	/* AT Attachment */
25374840Sken	PROTO_ATAPI,	/* AT Attachment Packetized Interface */
254195534Sscottl	PROTO_SATAPM,	/* SATA Port Multiplier */
255235897Smav	PROTO_SEMB,	/* SATA Enclosure Management Bridge */
25674840Sken} cam_proto;
25774840Sken
25874840Skentypedef enum {
25974840Sken	XPORT_UNKNOWN,
26074840Sken	XPORT_UNSPECIFIED,
26174840Sken	XPORT_SPI,	/* SCSI Parallel Interface */
26274840Sken	XPORT_FC,	/* Fiber Channel */
26374840Sken	XPORT_SSA,	/* Serial Storage Architecture */
26474840Sken	XPORT_USB,	/* Universal Serial Bus */
26574840Sken	XPORT_PPB,	/* Parallel Port Bus */
266154593Smjacob	XPORT_ATA,	/* AT Attachment */
267154593Smjacob	XPORT_SAS,	/* Serial Attached SCSI */
268195534Sscottl	XPORT_SATA,	/* Serial AT Attachment */
269196352Smav	XPORT_ISCSI,	/* iSCSI */
270255915Snwhitehorn	XPORT_SRP,	/* SCSI RDMA Protocol */
27174840Sken} cam_xport;
27274840Sken
273220644Smav#define XPORT_IS_ATA(t)		((t) == XPORT_ATA || (t) == XPORT_SATA)
274220644Smav#define XPORT_IS_SCSI(t)	((t) != XPORT_UNKNOWN && \
275220644Smav				 (t) != XPORT_UNSPECIFIED && \
276220644Smav				 !XPORT_IS_ATA(t))
277220644Smav#define XPORT_DEVSTAT_TYPE(t)	(XPORT_IS_ATA(t) ? DEVSTAT_TYPE_IF_IDE : \
278220644Smav				 XPORT_IS_SCSI(t) ? DEVSTAT_TYPE_IF_SCSI : \
279220644Smav				 DEVSTAT_TYPE_IF_OTHER)
280220644Smav
281154593Smjacob#define PROTO_VERSION_UNKNOWN (UINT_MAX - 1)
282154593Smjacob#define PROTO_VERSION_UNSPECIFIED UINT_MAX
283154593Smjacob#define XPORT_VERSION_UNKNOWN (UINT_MAX - 1)
284154593Smjacob#define XPORT_VERSION_UNSPECIFIED UINT_MAX
28574840Sken
28639212Sgibbstypedef union {
28760938Sjake	LIST_ENTRY(ccb_hdr) le;
28860938Sjake	SLIST_ENTRY(ccb_hdr) sle;
28960938Sjake	TAILQ_ENTRY(ccb_hdr) tqe;
29060938Sjake	STAILQ_ENTRY(ccb_hdr) stqe;
29139212Sgibbs} camq_entry;
29239212Sgibbs
29339212Sgibbstypedef union {
29439212Sgibbs	void		*ptr;
29539212Sgibbs	u_long		field;
296168752Sscottl	u_int8_t	bytes[sizeof(uintptr_t)];
29739212Sgibbs} ccb_priv_entry;
29839212Sgibbs
29939212Sgibbstypedef union {
30039212Sgibbs	ccb_priv_entry	entries[CCB_PERIPH_PRIV_SIZE];
30139212Sgibbs	u_int8_t	bytes[CCB_PERIPH_PRIV_SIZE * sizeof(ccb_priv_entry)];
30239212Sgibbs} ccb_ppriv_area;
30339212Sgibbs
30439212Sgibbstypedef union {
30539212Sgibbs	ccb_priv_entry	entries[CCB_SIM_PRIV_SIZE];
30639212Sgibbs	u_int8_t	bytes[CCB_SIM_PRIV_SIZE * sizeof(ccb_priv_entry)];
30739212Sgibbs} ccb_spriv_area;
30839212Sgibbs
309255870Sscottltypedef struct {
310255870Sscottl	struct timeval	*etime;
311255870Sscottl	uintptr_t	sim_data;
312255870Sscottl	uintptr_t	periph_data;
313255870Sscottl} ccb_qos_area;
314255870Sscottl
31539212Sgibbsstruct ccb_hdr {
316130200Sscottl	cam_pinfo	pinfo;		/* Info for priority scheduling */
31739212Sgibbs	camq_entry	xpt_links;	/* For chaining in the XPT layer */
31839212Sgibbs	camq_entry	sim_links;	/* For chaining in the SIM layer */
319130200Sscottl	camq_entry	periph_links;	/* For chaining in the type driver */
32039212Sgibbs	u_int32_t	retry_count;
32139212Sgibbs	void		(*cbfcnp)(struct cam_periph *, union ccb *);
322130200Sscottl					/* Callback on completion function */
32339212Sgibbs	xpt_opcode	func_code;	/* XPT function code */
324130200Sscottl	u_int32_t	status;		/* Status returned by CAM subsystem */
325130200Sscottl	struct		cam_path *path;	/* Compiled path for this ccb */
32639212Sgibbs	path_id_t	path_id;	/* Path ID for the request */
32739212Sgibbs	target_id_t	target_id;	/* Target device ID */
32839212Sgibbs	lun_id_t	target_lun;	/* Target LUN number */
329255870Sscottl	lun64_id_t	ext_lun;	/* 64bit extended/multi-level LUNs */
330130200Sscottl	u_int32_t	flags;		/* ccb_flags */
331255870Sscottl	u_int32_t	xflags;		/* Extended flags */
33239212Sgibbs	ccb_ppriv_area	periph_priv;
33339212Sgibbs	ccb_spriv_area	sim_priv;
334255870Sscottl	ccb_qos_area	qos;
335255870Sscottl	u_int32_t	timeout;	/* Hard timeout value in mseconds */
336255870Sscottl	struct timeval	softtimeout;	/* Soft timeout value in sec + usec */
33739212Sgibbs};
33839212Sgibbs
33939212Sgibbs/* Get Device Information CCB */
34039212Sgibbsstruct ccb_getdev {
34139212Sgibbs	struct	  ccb_hdr ccb_h;
342195534Sscottl	cam_proto protocol;
34356145Smjacob	struct scsi_inquiry_data inq_data;
344195534Sscottl	struct ata_params ident_data;
34539212Sgibbs	u_int8_t  serial_num[252];
346199178Smav	u_int8_t  inq_flags;
34739212Sgibbs	u_int8_t  serial_num_len;
34839212Sgibbs};
34939212Sgibbs
35047412Sgibbs/* Device Statistics CCB */
35147412Sgibbsstruct ccb_getdevstats {
35247412Sgibbs	struct	ccb_hdr	ccb_h;
35347412Sgibbs	int	dev_openings;	/* Space left for more work on device*/
35447412Sgibbs	int	dev_active;	/* Transactions running on the device */
35547412Sgibbs	int	devq_openings;	/* Space left for more queued work */
35647412Sgibbs	int	devq_queued;	/* Transactions queued to be sent */
35747412Sgibbs	int	held;		/*
35847412Sgibbs				 * CCBs held by peripheral drivers
35947412Sgibbs				 * for this device
36047412Sgibbs				 */
36147434Sgibbs	int	maxtags;	/*
36247434Sgibbs				 * Boundary conditions for number of
36347434Sgibbs				 * tagged operations
36447434Sgibbs				 */
36547434Sgibbs	int	mintags;
36647412Sgibbs	struct	timeval last_reset;	/* Time of last bus reset/loop init */
36747412Sgibbs};
36839212Sgibbs
36939212Sgibbstypedef enum {
37039212Sgibbs	CAM_GDEVLIST_LAST_DEVICE,
37139212Sgibbs	CAM_GDEVLIST_LIST_CHANGED,
37239212Sgibbs	CAM_GDEVLIST_MORE_DEVS,
37339212Sgibbs	CAM_GDEVLIST_ERROR
37439212Sgibbs} ccb_getdevlist_status_e;
37539212Sgibbs
37639212Sgibbsstruct ccb_getdevlist {
37739212Sgibbs	struct ccb_hdr		ccb_h;
37839212Sgibbs	char 			periph_name[DEV_IDLEN];
37939212Sgibbs	u_int32_t		unit_number;
38039212Sgibbs	unsigned int		generation;
38139212Sgibbs	u_int32_t		index;
38239212Sgibbs	ccb_getdevlist_status_e	status;
38339212Sgibbs};
38439212Sgibbs
38539212Sgibbstypedef enum {
38639212Sgibbs	PERIPH_MATCH_NONE	= 0x000,
38739212Sgibbs	PERIPH_MATCH_PATH	= 0x001,
38839212Sgibbs	PERIPH_MATCH_TARGET	= 0x002,
38939212Sgibbs	PERIPH_MATCH_LUN	= 0x004,
39039212Sgibbs	PERIPH_MATCH_NAME	= 0x008,
39139212Sgibbs	PERIPH_MATCH_UNIT	= 0x010,
39239212Sgibbs	PERIPH_MATCH_ANY	= 0x01f
39339212Sgibbs} periph_pattern_flags;
39439212Sgibbs
39539212Sgibbsstruct periph_match_pattern {
39639212Sgibbs	char			periph_name[DEV_IDLEN];
39739212Sgibbs	u_int32_t		unit_number;
39839212Sgibbs	path_id_t		path_id;
39939212Sgibbs	target_id_t		target_id;
40039212Sgibbs	lun_id_t		target_lun;
40139212Sgibbs	periph_pattern_flags	flags;
40239212Sgibbs};
40339212Sgibbs
40439212Sgibbstypedef enum {
40539212Sgibbs	DEV_MATCH_NONE		= 0x000,
40639212Sgibbs	DEV_MATCH_PATH		= 0x001,
40739212Sgibbs	DEV_MATCH_TARGET	= 0x002,
40839212Sgibbs	DEV_MATCH_LUN		= 0x004,
40939212Sgibbs	DEV_MATCH_INQUIRY	= 0x008,
410223081Sgibbs	DEV_MATCH_DEVID		= 0x010,
41139212Sgibbs	DEV_MATCH_ANY		= 0x00f
41239212Sgibbs} dev_pattern_flags;
41339212Sgibbs
414223081Sgibbsstruct device_id_match_pattern {
415223081Sgibbs	uint8_t id_len;
416223081Sgibbs	uint8_t id[256];
417223081Sgibbs};
418223081Sgibbs
41939212Sgibbsstruct device_match_pattern {
420223081Sgibbs	path_id_t					path_id;
421223081Sgibbs	target_id_t					target_id;
422223081Sgibbs	lun_id_t					target_lun;
423223081Sgibbs	dev_pattern_flags				flags;
424223081Sgibbs	union {
425223081Sgibbs		struct scsi_static_inquiry_pattern	inq_pat;
426223081Sgibbs		struct device_id_match_pattern		devid_pat;
427223081Sgibbs	} data;
42839212Sgibbs};
42939212Sgibbs
43039212Sgibbstypedef enum {
43139212Sgibbs	BUS_MATCH_NONE		= 0x000,
43239212Sgibbs	BUS_MATCH_PATH		= 0x001,
43339212Sgibbs	BUS_MATCH_NAME		= 0x002,
43439212Sgibbs	BUS_MATCH_UNIT		= 0x004,
43539212Sgibbs	BUS_MATCH_BUS_ID	= 0x008,
43639212Sgibbs	BUS_MATCH_ANY		= 0x00f
43739212Sgibbs} bus_pattern_flags;
43839212Sgibbs
43939212Sgibbsstruct bus_match_pattern {
44039212Sgibbs	path_id_t		path_id;
44139212Sgibbs	char			dev_name[DEV_IDLEN];
44239212Sgibbs	u_int32_t		unit_number;
44339212Sgibbs	u_int32_t		bus_id;
44439212Sgibbs	bus_pattern_flags	flags;
44539212Sgibbs};
44639212Sgibbs
44739212Sgibbsunion match_pattern {
44839212Sgibbs	struct periph_match_pattern	periph_pattern;
44939212Sgibbs	struct device_match_pattern	device_pattern;
45039212Sgibbs	struct bus_match_pattern	bus_pattern;
45139212Sgibbs};
45239212Sgibbs
45339212Sgibbstypedef enum {
45439212Sgibbs	DEV_MATCH_PERIPH,
45539212Sgibbs	DEV_MATCH_DEVICE,
45639212Sgibbs	DEV_MATCH_BUS
45739212Sgibbs} dev_match_type;
45839212Sgibbs
45939212Sgibbsstruct dev_match_pattern {
46039212Sgibbs	dev_match_type		type;
46139212Sgibbs	union match_pattern	pattern;
46239212Sgibbs};
46339212Sgibbs
46439212Sgibbsstruct periph_match_result {
46539212Sgibbs	char			periph_name[DEV_IDLEN];
46639212Sgibbs	u_int32_t		unit_number;
46739212Sgibbs	path_id_t		path_id;
46839212Sgibbs	target_id_t		target_id;
46939212Sgibbs	lun_id_t		target_lun;
47039212Sgibbs};
47139212Sgibbs
47246581Skentypedef enum {
47346581Sken	DEV_RESULT_NOFLAG		= 0x00,
47446581Sken	DEV_RESULT_UNCONFIGURED		= 0x01
47546581Sken} dev_result_flags;
47646581Sken
47739212Sgibbsstruct device_match_result {
47839212Sgibbs	path_id_t			path_id;
47939212Sgibbs	target_id_t			target_id;
48039212Sgibbs	lun_id_t			target_lun;
481195534Sscottl	cam_proto			protocol;
48239212Sgibbs	struct scsi_inquiry_data	inq_data;
483195534Sscottl	struct ata_params		ident_data;
48446581Sken	dev_result_flags		flags;
48539212Sgibbs};
48639212Sgibbs
48739212Sgibbsstruct bus_match_result {
48839212Sgibbs	path_id_t	path_id;
48939212Sgibbs	char		dev_name[DEV_IDLEN];
49039212Sgibbs	u_int32_t	unit_number;
49139212Sgibbs	u_int32_t	bus_id;
49239212Sgibbs};
49339212Sgibbs
49439212Sgibbsunion match_result {
49539212Sgibbs	struct periph_match_result	periph_result;
49639212Sgibbs	struct device_match_result	device_result;
49739212Sgibbs	struct bus_match_result		bus_result;
49839212Sgibbs};
49939212Sgibbs
50039212Sgibbsstruct dev_match_result {
50139212Sgibbs	dev_match_type		type;
50239212Sgibbs	union match_result	result;
50339212Sgibbs};
50439212Sgibbs
50539212Sgibbstypedef enum {
50639212Sgibbs	CAM_DEV_MATCH_LAST,
50739212Sgibbs	CAM_DEV_MATCH_MORE,
50839212Sgibbs	CAM_DEV_MATCH_LIST_CHANGED,
50939212Sgibbs	CAM_DEV_MATCH_SIZE_ERROR,
51039212Sgibbs	CAM_DEV_MATCH_ERROR
51139212Sgibbs} ccb_dev_match_status;
51239212Sgibbs
51339212Sgibbstypedef enum {
51439212Sgibbs	CAM_DEV_POS_NONE	= 0x000,
51539212Sgibbs	CAM_DEV_POS_BUS		= 0x001,
51639212Sgibbs	CAM_DEV_POS_TARGET	= 0x002,
51739212Sgibbs	CAM_DEV_POS_DEVICE	= 0x004,
51839212Sgibbs	CAM_DEV_POS_PERIPH	= 0x008,
51939212Sgibbs	CAM_DEV_POS_PDPTR	= 0x010,
52039212Sgibbs	CAM_DEV_POS_TYPEMASK	= 0xf00,
52139212Sgibbs	CAM_DEV_POS_EDT		= 0x100,
52239212Sgibbs	CAM_DEV_POS_PDRV	= 0x200
52339212Sgibbs} dev_pos_type;
52439212Sgibbs
52539212Sgibbsstruct ccb_dm_cookie {
52639212Sgibbs	void 	*bus;
52739212Sgibbs	void	*target;
52839212Sgibbs	void	*device;
52939212Sgibbs	void	*periph;
53039212Sgibbs	void	*pdrv;
53139212Sgibbs};
53239212Sgibbs
53339212Sgibbsstruct ccb_dev_position {
53439212Sgibbs	u_int			generations[4];
53539212Sgibbs#define	CAM_BUS_GENERATION	0x00
53639212Sgibbs#define CAM_TARGET_GENERATION	0x01
53739212Sgibbs#define CAM_DEV_GENERATION	0x02
53839212Sgibbs#define CAM_PERIPH_GENERATION	0x03
53939212Sgibbs	dev_pos_type		position_type;
54039212Sgibbs	struct ccb_dm_cookie	cookie;
54139212Sgibbs};
54239212Sgibbs
54339212Sgibbsstruct ccb_dev_match {
54439212Sgibbs	struct ccb_hdr			ccb_h;
54539212Sgibbs	ccb_dev_match_status		status;
54639212Sgibbs	u_int32_t			num_patterns;
54739212Sgibbs	u_int32_t			pattern_buf_len;
54839212Sgibbs	struct dev_match_pattern	*patterns;
54939212Sgibbs	u_int32_t			num_matches;
55039212Sgibbs	u_int32_t			match_buf_len;
55139212Sgibbs	struct dev_match_result		*matches;
55239212Sgibbs	struct ccb_dev_position		pos;
55339212Sgibbs};
55439212Sgibbs
55539212Sgibbs/*
55639212Sgibbs * Definitions for the path inquiry CCB fields.
55739212Sgibbs */
558255870Sscottl#define CAM_VERSION	0x18	/* Hex value for current version */
55939212Sgibbs
56039212Sgibbstypedef enum {
56139212Sgibbs	PI_MDP_ABLE	= 0x80,	/* Supports MDP message */
56239212Sgibbs	PI_WIDE_32	= 0x40,	/* Supports 32 bit wide SCSI */
56339212Sgibbs	PI_WIDE_16	= 0x20, /* Supports 16 bit wide SCSI */
56439212Sgibbs	PI_SDTR_ABLE	= 0x10,	/* Supports SDTR message */
56539212Sgibbs	PI_LINKED_CDB	= 0x08, /* Supports linked CDBs */
566195534Sscottl	PI_SATAPM	= 0x04,	/* Supports SATA PM */
56739212Sgibbs	PI_TAG_ABLE	= 0x02,	/* Supports tag queue messages */
56853258Sken	PI_SOFT_RST	= 0x01	/* Supports soft reset alternative */
56939212Sgibbs} pi_inqflag;
57039212Sgibbs
57139212Sgibbstypedef enum {
57239212Sgibbs	PIT_PROCESSOR	= 0x80,	/* Target mode processor mode */
57339212Sgibbs	PIT_PHASE	= 0x40,	/* Target mode phase cog. mode */
57439212Sgibbs	PIT_DISCONNECT	= 0x20,	/* Disconnects supported in target mode */
57539212Sgibbs	PIT_TERM_IO	= 0x10,	/* Terminate I/O message supported in TM */
57639212Sgibbs	PIT_GRP_6	= 0x08,	/* Group 6 commands supported */
57753258Sken	PIT_GRP_7	= 0x04	/* Group 7 commands supported */
57839212Sgibbs} pi_tmflag;
57939212Sgibbs
58039212Sgibbstypedef enum {
581255870Sscottl	PIM_EXTLUNS	= 0x100,/* 64bit extended LUNs supported */
58239212Sgibbs	PIM_SCANHILO	= 0x80,	/* Bus scans from high ID to low ID */
58339212Sgibbs	PIM_NOREMOVE	= 0x40,	/* Removeable devices not included in scan */
58441644Sgibbs	PIM_NOINITIATOR	= 0x20,	/* Initiator role not supported. */
585118105Snjl	PIM_NOBUSRESET	= 0x10,	/* User has disabled initial BUS RESET */
586159311Smjacob	PIM_NO_6_BYTE	= 0x08,	/* Do not send 6-byte commands */
587248519Skib	PIM_SEQSCAN	= 0x04,	/* Do bus scans sequentially, not in parallel */
588248519Skib	PIM_UNMAPPED	= 0x02,
589253549Sken	PIM_NOSCAN	= 0x01	/* SIM does its own scanning */
59039212Sgibbs} pi_miscflag;
59139212Sgibbs
59239212Sgibbs/* Path Inquiry CCB */
59374840Skenstruct ccb_pathinq_settings_spi {
59474840Sken	u_int8_t ppr_options;
59574840Sken};
596196008Smjacob
59777708Smjacobstruct ccb_pathinq_settings_fc {
59877708Smjacob	u_int64_t wwnn;		/* world wide node name */
59977708Smjacob	u_int64_t wwpn;		/* world wide port name */
60077708Smjacob	u_int32_t port;		/* 24 bit port id, if known */
60177708Smjacob	u_int32_t bitrate;	/* Mbps */
60277708Smjacob};
603196008Smjacob
604154593Smjacobstruct ccb_pathinq_settings_sas {
605154593Smjacob	u_int32_t bitrate;	/* Mbps */
606154593Smjacob};
60777708Smjacob#define	PATHINQ_SETTINGS_SIZE	128
60874840Sken
60939212Sgibbsstruct ccb_pathinq {
61039212Sgibbs	struct 	    ccb_hdr ccb_h;
61139212Sgibbs	u_int8_t    version_num;	/* Version number for the SIM/HBA */
61239212Sgibbs	u_int8_t    hba_inquiry;	/* Mimic of INQ byte 7 for the HBA */
613255870Sscottl	u_int16_t   target_sprt;	/* Flags for target mode support */
614255870Sscottl	u_int32_t   hba_misc;		/* Misc HBA features */
61539212Sgibbs	u_int16_t   hba_eng_cnt;	/* HBA engine count */
61639212Sgibbs					/* Vendor Unique capabilities */
61739212Sgibbs	u_int8_t    vuhba_flags[VUHBALEN];
61839212Sgibbs	u_int32_t   max_target;		/* Maximum supported Target */
61939212Sgibbs	u_int32_t   max_lun;		/* Maximum supported Lun */
62039212Sgibbs	u_int32_t   async_flags;	/* Installed Async handlers */
62139212Sgibbs	path_id_t   hpath_id;		/* Highest Path ID in the subsystem */
62239212Sgibbs	target_id_t initiator_id;	/* ID of the HBA on the SCSI bus */
62339212Sgibbs	char	    sim_vid[SIM_IDLEN];	/* Vendor ID of the SIM */
62439212Sgibbs	char	    hba_vid[HBA_IDLEN];	/* Vendor ID of the HBA */
62539212Sgibbs	char 	    dev_name[DEV_IDLEN];/* Device name for SIM */
62639212Sgibbs	u_int32_t   unit_number;	/* Unit number for SIM */
62739212Sgibbs	u_int32_t   bus_id;		/* Bus ID for SIM */
62846581Sken	u_int32_t   base_transfer_speed;/* Base bus speed in KB/sec */
62974840Sken	cam_proto   protocol;
63074840Sken	u_int	    protocol_version;
63174840Sken	cam_xport   transport;
63274840Sken	u_int	    transport_version;
63374840Sken	union {
63474840Sken		struct ccb_pathinq_settings_spi spi;
63577708Smjacob		struct ccb_pathinq_settings_fc fc;
636154593Smjacob		struct ccb_pathinq_settings_sas sas;
63777708Smjacob		char ccb_pathinq_settings_opaque[PATHINQ_SETTINGS_SIZE];
63874840Sken	} xport_specific;
639195534Sscottl	u_int		maxio;		/* Max supported I/O size, in bytes. */
640210471Smav	u_int16_t	hba_vendor;	/* HBA vendor ID */
641210471Smav	u_int16_t	hba_device;	/* HBA device ID */
642210471Smav	u_int16_t	hba_subvendor;	/* HBA subvendor ID */
643210471Smav	u_int16_t	hba_subdevice;	/* HBA subdevice ID */
64439212Sgibbs};
64539212Sgibbs
64647412Sgibbs/* Path Statistics CCB */
64747412Sgibbsstruct ccb_pathstats {
64847412Sgibbs	struct	ccb_hdr	ccb_h;
64947412Sgibbs	struct	timeval last_reset;	/* Time of last bus reset/loop init */
65047412Sgibbs};
65147412Sgibbs
652216088Skentypedef enum {
653216088Sken	SMP_FLAG_NONE		= 0x00,
654216088Sken	SMP_FLAG_REQ_SG		= 0x01,
655216088Sken	SMP_FLAG_RSP_SG		= 0x02
656216088Sken} ccb_smp_pass_flags;
657216088Sken
658216088Sken/*
659216088Sken * Serial Management Protocol CCB
660216088Sken * XXX Currently the semantics for this CCB are that it is executed either
661216088Sken * by the addressed device, or that device's parent (i.e. an expander for
662216088Sken * any device on an expander) if the addressed device doesn't support SMP.
663216088Sken * Later, once we have the ability to probe SMP-only devices and put them
664216088Sken * in CAM's topology, the CCB will only be executed by the addressed device
665216088Sken * if possible.
666216088Sken */
667216088Skenstruct ccb_smpio {
668216088Sken	struct ccb_hdr		ccb_h;
669216088Sken	uint8_t			*smp_request;
670216088Sken	int			smp_request_len;
671216088Sken	uint16_t		smp_request_sglist_cnt;
672216088Sken	uint8_t			*smp_response;
673216088Sken	int			smp_response_len;
674216088Sken	uint16_t		smp_response_sglist_cnt;
675216088Sken	ccb_smp_pass_flags	flags;
676216088Sken};
677216088Sken
67839212Sgibbstypedef union {
67939212Sgibbs	u_int8_t *sense_ptr;		/*
68039212Sgibbs					 * Pointer to storage
68139212Sgibbs					 * for sense information
68239212Sgibbs					 */
68339212Sgibbs	                                /* Storage Area for sense information */
68439212Sgibbs	struct	 scsi_sense_data sense_buf;
68539212Sgibbs} sense_t;
68639212Sgibbs
68739212Sgibbstypedef union {
68839212Sgibbs	u_int8_t  *cdb_ptr;		/* Pointer to the CDB bytes to send */
68939212Sgibbs					/* Area for the CDB send */
69039212Sgibbs	u_int8_t  cdb_bytes[IOCDBLEN];
69139212Sgibbs} cdb_t;
69239212Sgibbs
69339212Sgibbs/*
69439212Sgibbs * SCSI I/O Request CCB used for the XPT_SCSI_IO and XPT_CONT_TARGET_IO
69539212Sgibbs * function codes.
69639212Sgibbs */
69739212Sgibbsstruct ccb_scsiio {
69839212Sgibbs	struct	   ccb_hdr ccb_h;
69939212Sgibbs	union	   ccb *next_ccb;	/* Ptr for next CCB for action */
70039212Sgibbs	u_int8_t   *req_map;		/* Ptr to mapping info */
70139212Sgibbs	u_int8_t   *data_ptr;		/* Ptr to the data buf/SG list */
70239212Sgibbs	u_int32_t  dxfer_len;		/* Data transfer length */
70339212Sgibbs					/* Autosense storage */
70439212Sgibbs	struct     scsi_sense_data sense_data;
70539212Sgibbs	u_int8_t   sense_len;		/* Number of bytes to autosense */
70639212Sgibbs	u_int8_t   cdb_len;		/* Number of bytes for the CDB */
70739212Sgibbs	u_int16_t  sglist_cnt;		/* Number of SG list entries */
70839212Sgibbs	u_int8_t   scsi_status;		/* Returned SCSI status */
70939212Sgibbs	u_int8_t   sense_resid;		/* Autosense resid length: 2's comp */
71039212Sgibbs	u_int32_t  resid;		/* Transfer residual length: 2's comp */
71139212Sgibbs	cdb_t	   cdb_io;		/* Union for CDB bytes/pointer */
71239212Sgibbs	u_int8_t   *msg_ptr;		/* Pointer to the message buffer */
71339212Sgibbs	u_int16_t  msg_len;		/* Number of bytes for the Message */
71439212Sgibbs	u_int8_t   tag_action;		/* What to do for tag queueing */
71540417Sgibbs	/*
71640417Sgibbs	 * The tag action should be either the define below (to send a
71740417Sgibbs	 * non-tagged transaction) or one of the defined scsi tag messages
71840417Sgibbs	 * from scsi_message.h.
71940417Sgibbs	 */
72040417Sgibbs#define		CAM_TAG_ACTION_NONE	0x00
72149925Sgibbs	u_int	   tag_id;		/* tag id from initator (target mode) */
72249925Sgibbs	u_int	   init_id;		/* initiator id of who selected */
72339212Sgibbs};
72439212Sgibbs
725195534Sscottl/*
726195534Sscottl * ATA I/O Request CCB used for the XPT_ATA_IO function code.
727195534Sscottl */
728195534Sscottlstruct ccb_ataio {
729195534Sscottl	struct	   ccb_hdr ccb_h;
730195534Sscottl	union	   ccb *next_ccb;	/* Ptr for next CCB for action */
731195534Sscottl	struct ata_cmd	cmd;		/* ATA command register set */
732195534Sscottl	struct ata_res	res;		/* ATA result register set */
733195534Sscottl	u_int8_t   *data_ptr;		/* Ptr to the data buf/SG list */
734195534Sscottl	u_int32_t  dxfer_len;		/* Data transfer length */
735195534Sscottl	u_int32_t  resid;		/* Transfer residual length: 2's comp */
736195534Sscottl	u_int8_t   tag_action;		/* What to do for tag queueing */
737195534Sscottl	/*
738195534Sscottl	 * The tag action should be either the define below (to send a
739195534Sscottl	 * non-tagged transaction) or one of the defined scsi tag messages
740195534Sscottl	 * from scsi_message.h.
741195534Sscottl	 */
742195534Sscottl#define		CAM_TAG_ACTION_NONE	0x00
743195534Sscottl	u_int	   tag_id;		/* tag id from initator (target mode) */
744195534Sscottl	u_int	   init_id;		/* initiator id of who selected */
745195534Sscottl};
746195534Sscottl
74739212Sgibbsstruct ccb_accept_tio {
74839212Sgibbs	struct	   ccb_hdr ccb_h;
74939212Sgibbs	cdb_t	   cdb_io;		/* Union for CDB bytes/pointer */
75039212Sgibbs	u_int8_t   cdb_len;		/* Number of bytes for the CDB */
75139212Sgibbs	u_int8_t   tag_action;		/* What to do for tag queueing */
75256145Smjacob	u_int8_t   sense_len;		/* Number of bytes of Sense Data */
75355328Smjacob	u_int      tag_id;		/* tag id from initator (target mode) */
75455328Smjacob	u_int      init_id;		/* initiator id of who selected */
75556145Smjacob	struct     scsi_sense_data sense_data;
75639212Sgibbs};
75739212Sgibbs
75839212Sgibbs/* Release SIM Queue */
75939212Sgibbsstruct ccb_relsim {
76039212Sgibbs	struct ccb_hdr ccb_h;
76139212Sgibbs	u_int32_t      release_flags;
76239212Sgibbs#define RELSIM_ADJUST_OPENINGS		0x01
76339212Sgibbs#define RELSIM_RELEASE_AFTER_TIMEOUT	0x02
76439212Sgibbs#define RELSIM_RELEASE_AFTER_CMDCMPLT	0x04
76539212Sgibbs#define RELSIM_RELEASE_AFTER_QEMPTY	0x08
76639212Sgibbs	u_int32_t      openings;
767203108Smav	u_int32_t      release_timeout;	/* Abstract argument. */
76839212Sgibbs	u_int32_t      qfrozen_cnt;
76939212Sgibbs};
77039212Sgibbs
77139212Sgibbs/*
77239212Sgibbs * Definitions for the asynchronous callback CCB fields.
77339212Sgibbs */
77439212Sgibbstypedef enum {
775238886Smav	AC_UNIT_ATTENTION	= 0x4000,/* Device reported UNIT ATTENTION */
776223081Sgibbs	AC_ADVINFO_CHANGED	= 0x2000,/* Advance info might have changes */
777196008Smjacob	AC_CONTRACT		= 0x1000,/* A contractual callback */
77839212Sgibbs	AC_GETDEV_CHANGED	= 0x800,/* Getdev info might have changed */
77939212Sgibbs	AC_INQ_CHANGED		= 0x400,/* Inquiry info might have changed */
78039212Sgibbs	AC_TRANSFER_NEG		= 0x200,/* New transfer settings in effect */
78139212Sgibbs	AC_LOST_DEVICE		= 0x100,/* A device went away */
78239212Sgibbs	AC_FOUND_DEVICE		= 0x080,/* A new device was found */
78339212Sgibbs	AC_PATH_DEREGISTERED	= 0x040,/* A path has de-registered */
78439212Sgibbs	AC_PATH_REGISTERED	= 0x020,/* A new path has been registered */
78539212Sgibbs	AC_SENT_BDR		= 0x010,/* A BDR message was sent to target */
78639212Sgibbs	AC_SCSI_AEN		= 0x008,/* A SCSI AEN has been received */
78739212Sgibbs	AC_UNSOL_RESEL		= 0x002,/* Unsolicited reselection occurred */
78839212Sgibbs	AC_BUS_RESET		= 0x001	/* A SCSI bus reset occurred */
78939212Sgibbs} ac_code;
79039212Sgibbs
79139212Sgibbstypedef void ac_callback_t (void *softc, u_int32_t code,
79239212Sgibbs			    struct cam_path *path, void *args);
79339212Sgibbs
794196008Smjacob/*
795196008Smjacob * Generic Asynchronous callbacks.
796196008Smjacob *
797196008Smjacob * Generic arguments passed bac which are then interpreted between a per-system
798196008Smjacob * contract number.
799196008Smjacob */
800196008Smjacob#define	AC_CONTRACT_DATA_MAX (128 - sizeof (u_int64_t))
801196008Smjacobstruct ac_contract {
802196008Smjacob	u_int64_t	contract_number;
803196008Smjacob	u_int8_t	contract_data[AC_CONTRACT_DATA_MAX];
804196008Smjacob};
805196008Smjacob
806196008Smjacob#define	AC_CONTRACT_DEV_CHG	1
807196008Smjacobstruct ac_device_changed {
808196008Smjacob	u_int64_t	wwpn;
809196008Smjacob	u_int32_t	port;
810196008Smjacob	target_id_t	target;
811196008Smjacob	u_int8_t	arrived;
812196008Smjacob};
813196008Smjacob
81439212Sgibbs/* Set Asynchronous Callback CCB */
81539212Sgibbsstruct ccb_setasync {
81639212Sgibbs	struct ccb_hdr	 ccb_h;
81739212Sgibbs	u_int32_t	 event_enable;	/* Async Event enables */
81839212Sgibbs	ac_callback_t	*callback;
81939212Sgibbs	void		*callback_arg;
82039212Sgibbs};
82139212Sgibbs
82239212Sgibbs/* Set Device Type CCB */
82339212Sgibbsstruct ccb_setdev {
82439212Sgibbs	struct	   ccb_hdr ccb_h;
82539212Sgibbs	u_int8_t   dev_type;	/* Value for dev type field in EDT */
82639212Sgibbs};
82739212Sgibbs
82839212Sgibbs/* SCSI Control Functions */
82939212Sgibbs
83039212Sgibbs/* Abort XPT request CCB */
83139212Sgibbsstruct ccb_abort {
83239212Sgibbs	struct 	ccb_hdr ccb_h;
83339212Sgibbs	union	ccb *abort_ccb;	/* Pointer to CCB to abort */
83439212Sgibbs};
83539212Sgibbs
83639212Sgibbs/* Reset SCSI Bus CCB */
83739212Sgibbsstruct ccb_resetbus {
83839212Sgibbs	struct	ccb_hdr ccb_h;
83939212Sgibbs};
84039212Sgibbs
84139212Sgibbs/* Reset SCSI Device CCB */
84239212Sgibbsstruct ccb_resetdev {
84339212Sgibbs	struct	ccb_hdr ccb_h;
84439212Sgibbs};
84539212Sgibbs
84639212Sgibbs/* Terminate I/O Process Request CCB */
84739212Sgibbsstruct ccb_termio {
84839212Sgibbs	struct	ccb_hdr ccb_h;
84939212Sgibbs	union	ccb *termio_ccb;	/* Pointer to CCB to terminate */
85039212Sgibbs};
85139212Sgibbs
85274840Skentypedef enum {
85374840Sken	CTS_TYPE_CURRENT_SETTINGS,
85474840Sken	CTS_TYPE_USER_SETTINGS
85574840Sken} cts_type;
85674840Sken
85774840Skenstruct ccb_trans_settings_scsi
85874840Sken{
85939212Sgibbs	u_int	valid;	/* Which fields to honor */
86074840Sken#define	CTS_SCSI_VALID_TQ		0x01
86139212Sgibbs	u_int	flags;
86274840Sken#define	CTS_SCSI_FLAGS_TAG_ENB		0x01
86374840Sken};
86474840Sken
865236437Smavstruct ccb_trans_settings_ata
866236437Smav{
867236437Smav	u_int	valid;	/* Which fields to honor */
868236437Smav#define	CTS_ATA_VALID_TQ		0x01
869236437Smav	u_int	flags;
870236437Smav#define	CTS_ATA_FLAGS_TAG_ENB		0x01
871236437Smav};
872236437Smav
87374840Skenstruct ccb_trans_settings_spi
87474840Sken{
87574840Sken	u_int	  valid;	/* Which fields to honor */
87674840Sken#define	CTS_SPI_VALID_SYNC_RATE		0x01
87774840Sken#define	CTS_SPI_VALID_SYNC_OFFSET	0x02
87874840Sken#define	CTS_SPI_VALID_BUS_WIDTH		0x04
87974840Sken#define	CTS_SPI_VALID_DISC		0x08
88074840Sken#define CTS_SPI_VALID_PPR_OPTIONS	0x10
88174840Sken	u_int	flags;
88274840Sken#define	CTS_SPI_FLAGS_DISC_ENB		0x01
88339212Sgibbs	u_int	sync_period;
88439212Sgibbs	u_int	sync_offset;
88539212Sgibbs	u_int	bus_width;
88674840Sken	u_int	ppr_options;
88739212Sgibbs};
88839212Sgibbs
88978709Smjacobstruct ccb_trans_settings_fc {
89078709Smjacob	u_int     	valid;		/* Which fields to honor */
89178709Smjacob#define	CTS_FC_VALID_WWNN		0x8000
89278709Smjacob#define	CTS_FC_VALID_WWPN		0x4000
89378709Smjacob#define	CTS_FC_VALID_PORT		0x2000
89478709Smjacob#define	CTS_FC_VALID_SPEED		0x1000
89578709Smjacob	u_int64_t	wwnn;		/* world wide node name */
89678709Smjacob	u_int64_t 	wwpn;		/* world wide port name */
89778709Smjacob	u_int32_t 	port;		/* 24 bit port id, if known */
89878709Smjacob	u_int32_t 	bitrate;	/* Mbps */
89978709Smjacob};
90078709Smjacob
901154593Smjacobstruct ccb_trans_settings_sas {
902154593Smjacob	u_int     	valid;		/* Which fields to honor */
903154593Smjacob#define	CTS_SAS_VALID_SPEED		0x1000
904154593Smjacob	u_int32_t 	bitrate;	/* Mbps */
905154593Smjacob};
906154593Smjacob
907236437Smavstruct ccb_trans_settings_pata {
908198708Smav	u_int     	valid;		/* Which fields to honor */
909198708Smav#define	CTS_ATA_VALID_MODE		0x01
910199747Smav#define	CTS_ATA_VALID_BYTECOUNT		0x02
911203376Smav#define	CTS_ATA_VALID_ATAPI		0x20
912249199Smarius#define	CTS_ATA_VALID_CAPS		0x40
913199821Smav	int		mode;		/* Mode */
914198708Smav	u_int 		bytecount;	/* Length of PIO transaction */
915203376Smav	u_int 		atapi;		/* Length of ATAPI CDB */
916249199Smarius	u_int 		caps;		/* Device and host SATA caps. */
917249199Smarius#define	CTS_ATA_CAPS_H			0x0000ffff
918249199Smarius#define	CTS_ATA_CAPS_H_DMA48		0x00000001 /* 48-bit DMA */
919249199Smarius#define	CTS_ATA_CAPS_D			0xffff0000
920198708Smav};
921198708Smav
922195534Sscottlstruct ccb_trans_settings_sata {
923195534Sscottl	u_int     	valid;		/* Which fields to honor */
924199747Smav#define	CTS_SATA_VALID_MODE		0x01
925199747Smav#define	CTS_SATA_VALID_BYTECOUNT	0x02
926199747Smav#define	CTS_SATA_VALID_REVISION		0x04
927199747Smav#define	CTS_SATA_VALID_PM		0x08
928199747Smav#define	CTS_SATA_VALID_TAGS		0x10
929203376Smav#define	CTS_SATA_VALID_ATAPI		0x20
930207499Smav#define	CTS_SATA_VALID_CAPS		0x40
931199821Smav	int		mode;		/* Legacy PATA mode */
932199747Smav	u_int 		bytecount;	/* Length of PIO transaction */
933199821Smav	int		revision;	/* SATA revision */
934195534Sscottl	u_int 		pm_present;	/* PM is present (XPT->SIM) */
935199747Smav	u_int 		tags;		/* Number of allowed tags */
936203376Smav	u_int 		atapi;		/* Length of ATAPI CDB */
937207499Smav	u_int 		caps;		/* Device and host SATA caps. */
938207499Smav#define	CTS_SATA_CAPS_H			0x0000ffff
939207499Smav#define	CTS_SATA_CAPS_H_PMREQ		0x00000001
940207499Smav#define	CTS_SATA_CAPS_H_APST		0x00000002
941207499Smav#define	CTS_SATA_CAPS_H_DMAAA		0x00000010 /* Auto-activation */
942220602Smav#define	CTS_SATA_CAPS_H_AN		0x00000020 /* Async. notification */
943207499Smav#define	CTS_SATA_CAPS_D			0xffff0000
944207499Smav#define	CTS_SATA_CAPS_D_PMREQ		0x00010000
945207499Smav#define	CTS_SATA_CAPS_D_APST		0x00020000
946195534Sscottl};
947154593Smjacob
94874840Sken/* Get/Set transfer rate/width/disconnection/tag queueing settings */
94974840Skenstruct ccb_trans_settings {
95074840Sken	struct	  ccb_hdr ccb_h;
95174840Sken	cts_type  type;		/* Current or User settings */
95274840Sken	cam_proto protocol;
95374840Sken	u_int	  protocol_version;
95474840Sken	cam_xport transport;
95574840Sken	u_int	  transport_version;
95674840Sken	union {
95774840Sken		u_int  valid;	/* Which fields to honor */
958236437Smav		struct ccb_trans_settings_ata ata;
95974840Sken		struct ccb_trans_settings_scsi scsi;
96074840Sken	} proto_specific;
96174840Sken	union {
96274840Sken		u_int  valid;	/* Which fields to honor */
96374840Sken		struct ccb_trans_settings_spi spi;
96478709Smjacob		struct ccb_trans_settings_fc fc;
965154593Smjacob		struct ccb_trans_settings_sas sas;
966236437Smav		struct ccb_trans_settings_pata ata;
967195534Sscottl		struct ccb_trans_settings_sata sata;
96874840Sken	} xport_specific;
96974840Sken};
97074840Sken
97174840Sken
97239212Sgibbs/*
97339212Sgibbs * Calculate the geometry parameters for a device
97439212Sgibbs * give the block size and volume size in blocks.
97539212Sgibbs */
97639212Sgibbsstruct ccb_calc_geometry {
97739212Sgibbs	struct	  ccb_hdr ccb_h;
97839212Sgibbs	u_int32_t block_size;
979114261Sken	u_int64_t volume_size;
980114261Sken	u_int32_t cylinders;
98139212Sgibbs	u_int8_t  heads;
98239212Sgibbs	u_int8_t  secs_per_track;
98339212Sgibbs};
98439212Sgibbs
98539212Sgibbs/*
986196008Smjacob * Set or get SIM (and transport) specific knobs
987196008Smjacob */
988196008Smjacob
989196008Smjacob#define	KNOB_VALID_ADDRESS	0x1
990196008Smjacob#define	KNOB_VALID_ROLE		0x2
991196008Smjacob
992196008Smjacob
993196008Smjacob#define	KNOB_ROLE_NONE		0x0
994196008Smjacob#define	KNOB_ROLE_INITIATOR	0x1
995196008Smjacob#define	KNOB_ROLE_TARGET	0x2
996196008Smjacob#define	KNOB_ROLE_BOTH		0x3
997196008Smjacob
998196008Smjacobstruct ccb_sim_knob_settings_spi {
999196008Smjacob	u_int		valid;
1000196008Smjacob	u_int		initiator_id;
1001196008Smjacob	u_int		role;
1002196008Smjacob};
1003196008Smjacob
1004196008Smjacobstruct ccb_sim_knob_settings_fc {
1005196008Smjacob	u_int		valid;
1006196008Smjacob	u_int64_t	wwnn;		/* world wide node name */
1007196008Smjacob	u_int64_t 	wwpn;		/* world wide port name */
1008196008Smjacob	u_int		role;
1009196008Smjacob};
1010196008Smjacob
1011196008Smjacobstruct ccb_sim_knob_settings_sas {
1012196008Smjacob	u_int		valid;
1013196008Smjacob	u_int64_t	wwnn;		/* world wide node name */
1014196008Smjacob	u_int		role;
1015196008Smjacob};
1016196008Smjacob#define	KNOB_SETTINGS_SIZE	128
1017196008Smjacob
1018196008Smjacobstruct ccb_sim_knob {
1019196008Smjacob	struct	  ccb_hdr ccb_h;
1020196008Smjacob	union {
1021196008Smjacob		u_int  valid;	/* Which fields to honor */
1022196008Smjacob		struct ccb_sim_knob_settings_spi spi;
1023196008Smjacob		struct ccb_sim_knob_settings_fc fc;
1024196008Smjacob		struct ccb_sim_knob_settings_sas sas;
1025196008Smjacob		char pad[KNOB_SETTINGS_SIZE];
1026196008Smjacob	} xport_specific;
1027196008Smjacob};
1028196008Smjacob
1029196008Smjacob/*
103039212Sgibbs * Rescan the given bus, or bus/target/lun
103139212Sgibbs */
103239212Sgibbsstruct ccb_rescan {
103339212Sgibbs	struct	ccb_hdr ccb_h;
103439212Sgibbs	cam_flags	flags;
103539212Sgibbs};
103639212Sgibbs
103739212Sgibbs/*
103839212Sgibbs * Turn on debugging for the given bus, bus/target, or bus/target/lun.
103939212Sgibbs */
104039212Sgibbsstruct ccb_debug {
104139212Sgibbs	struct	ccb_hdr ccb_h;
104239212Sgibbs	cam_debug_flags flags;
104339212Sgibbs};
104439212Sgibbs
104539212Sgibbs/* Target mode structures. */
104639212Sgibbs
104739212Sgibbsstruct ccb_en_lun {
104839212Sgibbs	struct	  ccb_hdr ccb_h;
104939212Sgibbs	u_int16_t grp6_len;		/* Group 6 VU CDB length */
105039212Sgibbs	u_int16_t grp7_len;		/* Group 7 VU CDB length */
105139212Sgibbs	u_int8_t  enable;
105239212Sgibbs};
105339212Sgibbs
1054196008Smjacob/* old, barely used immediate notify, binary compatibility */
105539212Sgibbsstruct ccb_immed_notify {
105639212Sgibbs	struct	  ccb_hdr ccb_h;
105739212Sgibbs	struct    scsi_sense_data sense_data;
105856145Smjacob	u_int8_t  sense_len;		/* Number of bytes in sense buffer */
105939212Sgibbs	u_int8_t  initiator_id;		/* Id of initiator that selected */
106039212Sgibbs	u_int8_t  message_args[7];	/* Message Arguments */
106139212Sgibbs};
106239212Sgibbs
106339212Sgibbsstruct ccb_notify_ack {
106439212Sgibbs	struct	  ccb_hdr ccb_h;
106539212Sgibbs	u_int16_t seq_id;		/* Sequence identifier */
106639212Sgibbs	u_int8_t  event;		/* Event flags */
106739212Sgibbs};
106839212Sgibbs
1069196008Smjacobstruct ccb_immediate_notify {
1070196008Smjacob	struct    ccb_hdr ccb_h;
1071196008Smjacob	u_int     tag_id;		/* Tag for immediate notify */
1072196008Smjacob	u_int     seq_id;		/* Tag for target of notify */
1073196008Smjacob	u_int     initiator_id;		/* Initiator Identifier */
1074196008Smjacob	u_int     arg;			/* Function specific */
1075196008Smjacob};
1076196008Smjacob
1077196008Smjacobstruct ccb_notify_acknowledge {
1078196008Smjacob	struct    ccb_hdr ccb_h;
1079196008Smjacob	u_int     tag_id;		/* Tag for immediate notify */
1080196008Smjacob	u_int     seq_id;		/* Tar for target of notify */
1081196008Smjacob	u_int     initiator_id;		/* Initiator Identifier */
1082196008Smjacob	u_int     arg;			/* Function specific */
1083196008Smjacob};
1084196008Smjacob
108539212Sgibbs/* HBA engine structures. */
108639212Sgibbs
108739212Sgibbstypedef enum {
108839212Sgibbs	EIT_BUFFER,	/* Engine type: buffer memory */
108939212Sgibbs	EIT_LOSSLESS,	/* Engine type: lossless compression */
109039212Sgibbs	EIT_LOSSY,	/* Engine type: lossy compression */
109139212Sgibbs	EIT_ENCRYPT	/* Engine type: encryption */
109239212Sgibbs} ei_type;
109339212Sgibbs
109439212Sgibbstypedef enum {
109539212Sgibbs	EAD_VUNIQUE,	/* Engine algorithm ID: vendor unique */
109639212Sgibbs	EAD_LZ1V1,	/* Engine algorithm ID: LZ1 var.1 */
109739212Sgibbs	EAD_LZ2V1,	/* Engine algorithm ID: LZ2 var.1 */
109853258Sken	EAD_LZ2V2	/* Engine algorithm ID: LZ2 var.2 */
109939212Sgibbs} ei_algo;
110039212Sgibbs
110139212Sgibbsstruct ccb_eng_inq {
110239212Sgibbs	struct	  ccb_hdr ccb_h;
110339212Sgibbs	u_int16_t eng_num;	/* The engine number for this inquiry */
110439212Sgibbs	ei_type   eng_type;	/* Returned engine type */
110539212Sgibbs	ei_algo   eng_algo;	/* Returned engine algorithm type */
110639212Sgibbs	u_int32_t eng_memeory;	/* Returned engine memory size */
110739212Sgibbs};
110839212Sgibbs
110939212Sgibbsstruct ccb_eng_exec {	/* This structure must match SCSIIO size */
111039212Sgibbs	struct	  ccb_hdr ccb_h;
111139212Sgibbs	u_int8_t  *pdrv_ptr;	/* Ptr used by the peripheral driver */
111239212Sgibbs	u_int8_t  *req_map;	/* Ptr for mapping info on the req. */
111339212Sgibbs	u_int8_t  *data_ptr;	/* Pointer to the data buf/SG list */
111439212Sgibbs	u_int32_t dxfer_len;	/* Data transfer length */
111539212Sgibbs	u_int8_t  *engdata_ptr;	/* Pointer to the engine buffer data */
111639212Sgibbs	u_int16_t sglist_cnt;	/* Num of scatter gather list entries */
111739212Sgibbs	u_int32_t dmax_len;	/* Destination data maximum length */
111839212Sgibbs	u_int32_t dest_len;	/* Destination data length */
111939212Sgibbs	int32_t	  src_resid;	/* Source residual length: 2's comp */
112039212Sgibbs	u_int32_t timeout;	/* Timeout value */
112139212Sgibbs	u_int16_t eng_num;	/* Engine number for this request */
112239212Sgibbs	u_int16_t vu_flags;	/* Vendor Unique flags */
112339212Sgibbs};
112439212Sgibbs
112539212Sgibbs/*
112639212Sgibbs * Definitions for the timeout field in the SCSI I/O CCB.
112739212Sgibbs */
112839212Sgibbs#define	CAM_TIME_DEFAULT	0x00000000	/* Use SIM default value */
112939212Sgibbs#define	CAM_TIME_INFINITY	0xFFFFFFFF	/* Infinite timeout */
113039212Sgibbs
113139212Sgibbs#define	CAM_SUCCESS	0	/* For signaling general success */
113239212Sgibbs#define	CAM_FAILURE	1	/* For signaling general failure */
113339212Sgibbs
113439212Sgibbs#define CAM_FALSE	0
113539212Sgibbs#define CAM_TRUE	1
113639212Sgibbs
113739212Sgibbs#define XPT_CCB_INVALID	-1	/* for signaling a bad CCB to free */
113839212Sgibbs
113939212Sgibbs/*
1140223081Sgibbs * CCB for working with advanced device information.  This operates in a fashion
1141216088Sken * similar to XPT_GDEV_TYPE.  Specify the target in ccb_h, the buffer
1142216088Sken * type requested, and provide a buffer size/buffer to write to.  If the
1143223081Sgibbs * buffer is too small, provsiz will be larger than bufsiz.
1144216088Sken */
1145223081Sgibbsstruct ccb_dev_advinfo {
1146216088Sken	struct ccb_hdr ccb_h;
1147216088Sken	uint32_t flags;
1148223081Sgibbs#define	CDAI_FLAG_STORE		0x1	/* If set, action becomes store */
1149216088Sken	uint32_t buftype;		/* IN: Type of data being requested */
1150216088Sken	/* NB: buftype is interpreted on a per-transport basis */
1151223081Sgibbs#define	CDAI_TYPE_SCSI_DEVID	1
1152223081Sgibbs#define	CDAI_TYPE_SERIAL_NUM	2
1153223081Sgibbs#define	CDAI_TYPE_PHYS_PATH	3
1154230590Sken#define	CDAI_TYPE_RCAPLONG	4
1155216088Sken	off_t bufsiz;			/* IN: Size of external buffer */
1156216088Sken#define	CAM_SCSI_DEVID_MAXLEN	65536	/* length in buffer is an uint16_t */
1157216088Sken	off_t provsiz;			/* OUT: Size required/used */
1158216088Sken	uint8_t *buf;			/* IN/OUT: Buffer for requested data */
1159216088Sken};
1160216088Sken
1161216088Sken/*
1162260387Sscottl * CCB for sending async events
1163260387Sscottl */
1164260387Sscottlstruct ccb_async {
1165260387Sscottl	struct ccb_hdr ccb_h;
1166260387Sscottl	uint32_t async_code;
1167260387Sscottl	off_t async_arg_size;
1168260387Sscottl	void *async_arg_ptr;
1169260387Sscottl};
1170260387Sscottl
1171260387Sscottl/*
117239212Sgibbs * Union of all CCB types for kernel space allocation.  This union should
117339212Sgibbs * never be used for manipulating CCBs - its only use is for the allocation
117439212Sgibbs * and deallocation of raw CCB space and is the return type of xpt_ccb_alloc
117539212Sgibbs * and the argument to xpt_ccb_free.
117639212Sgibbs */
117739212Sgibbsunion ccb {
117839212Sgibbs	struct	ccb_hdr			ccb_h;	/* For convenience */
117939212Sgibbs	struct	ccb_scsiio		csio;
118039212Sgibbs	struct	ccb_getdev		cgd;
118139212Sgibbs	struct	ccb_getdevlist		cgdl;
118239212Sgibbs	struct	ccb_pathinq		cpi;
118339212Sgibbs	struct	ccb_relsim		crs;
118439212Sgibbs	struct	ccb_setasync		csa;
118539212Sgibbs	struct	ccb_setdev		csd;
118647412Sgibbs	struct	ccb_pathstats		cpis;
118747412Sgibbs	struct	ccb_getdevstats		cgds;
118839212Sgibbs	struct	ccb_dev_match		cdm;
118939212Sgibbs	struct	ccb_trans_settings	cts;
119039212Sgibbs	struct	ccb_calc_geometry	ccg;
1191196008Smjacob	struct	ccb_sim_knob		knob;
119239212Sgibbs	struct	ccb_abort		cab;
119339212Sgibbs	struct	ccb_resetbus		crb;
119439212Sgibbs	struct	ccb_resetdev		crd;
119539212Sgibbs	struct	ccb_termio		tio;
119639212Sgibbs	struct	ccb_accept_tio		atio;
119739212Sgibbs	struct	ccb_scsiio		ctio;
119839212Sgibbs	struct	ccb_en_lun		cel;
119939212Sgibbs	struct	ccb_immed_notify	cin;
120039212Sgibbs	struct	ccb_notify_ack		cna;
1201196008Smjacob	struct	ccb_immediate_notify	cin1;
1202196008Smjacob	struct	ccb_notify_acknowledge	cna2;
120339212Sgibbs	struct	ccb_eng_inq		cei;
120439212Sgibbs	struct	ccb_eng_exec		cee;
1205216088Sken	struct	ccb_smpio		smpio;
120639212Sgibbs	struct 	ccb_rescan		crcn;
120739212Sgibbs	struct  ccb_debug		cdbg;
1208195534Sscottl	struct	ccb_ataio		ataio;
1209223081Sgibbs	struct	ccb_dev_advinfo		cdai;
1210260387Sscottl	struct	ccb_async		casync;
121139212Sgibbs};
121239212Sgibbs
121339212Sgibbs__BEGIN_DECLS
121439212Sgibbsstatic __inline void
121539212Sgibbscam_fill_csio(struct ccb_scsiio *csio, u_int32_t retries,
121639212Sgibbs	      void (*cbfcnp)(struct cam_periph *, union ccb *),
121739212Sgibbs	      u_int32_t flags, u_int8_t tag_action,
121839212Sgibbs	      u_int8_t *data_ptr, u_int32_t dxfer_len,
121939212Sgibbs	      u_int8_t sense_len, u_int8_t cdb_len,
122039212Sgibbs	      u_int32_t timeout);
122139212Sgibbs
122239212Sgibbsstatic __inline void
122339212Sgibbscam_fill_ctio(struct ccb_scsiio *csio, u_int32_t retries,
122439212Sgibbs	      void (*cbfcnp)(struct cam_periph *, union ccb *),
122539212Sgibbs	      u_int32_t flags, u_int tag_action, u_int tag_id,
122639212Sgibbs	      u_int init_id, u_int scsi_status, u_int8_t *data_ptr,
122739212Sgibbs	      u_int32_t dxfer_len, u_int32_t timeout);
1228195534Sscottl
122939212Sgibbsstatic __inline void
1230195534Sscottlcam_fill_ataio(struct ccb_ataio *ataio, u_int32_t retries,
1231195534Sscottl	      void (*cbfcnp)(struct cam_periph *, union ccb *),
1232195534Sscottl	      u_int32_t flags, u_int tag_action,
1233195534Sscottl	      u_int8_t *data_ptr, u_int32_t dxfer_len,
1234195534Sscottl	      u_int32_t timeout);
1235195534Sscottl
1236195534Sscottlstatic __inline void
1237216088Skencam_fill_smpio(struct ccb_smpio *smpio, uint32_t retries,
1238216088Sken	       void (*cbfcnp)(struct cam_periph *, union ccb *), uint32_t flags,
1239216088Sken	       uint8_t *smp_request, int smp_request_len,
1240216088Sken	       uint8_t *smp_response, int smp_response_len,
1241216088Sken	       uint32_t timeout);
1242216088Sken
1243216088Skenstatic __inline void
124439212Sgibbscam_fill_csio(struct ccb_scsiio *csio, u_int32_t retries,
124539212Sgibbs	      void (*cbfcnp)(struct cam_periph *, union ccb *),
124639212Sgibbs	      u_int32_t flags, u_int8_t tag_action,
124739212Sgibbs	      u_int8_t *data_ptr, u_int32_t dxfer_len,
124839212Sgibbs	      u_int8_t sense_len, u_int8_t cdb_len,
124939212Sgibbs	      u_int32_t timeout)
125039212Sgibbs{
125139212Sgibbs	csio->ccb_h.func_code = XPT_SCSI_IO;
125239212Sgibbs	csio->ccb_h.flags = flags;
1253255915Snwhitehorn	csio->ccb_h.xflags = 0;
125439212Sgibbs	csio->ccb_h.retry_count = retries;
125539212Sgibbs	csio->ccb_h.cbfcnp = cbfcnp;
125639212Sgibbs	csio->ccb_h.timeout = timeout;
125739212Sgibbs	csio->data_ptr = data_ptr;
125839212Sgibbs	csio->dxfer_len = dxfer_len;
125939212Sgibbs	csio->sense_len = sense_len;
126039212Sgibbs	csio->cdb_len = cdb_len;
126139212Sgibbs	csio->tag_action = tag_action;
126239212Sgibbs}
126339212Sgibbs
126439212Sgibbsstatic __inline void
126539212Sgibbscam_fill_ctio(struct ccb_scsiio *csio, u_int32_t retries,
126639212Sgibbs	      void (*cbfcnp)(struct cam_periph *, union ccb *),
126739212Sgibbs	      u_int32_t flags, u_int tag_action, u_int tag_id,
126839212Sgibbs	      u_int init_id, u_int scsi_status, u_int8_t *data_ptr,
126939212Sgibbs	      u_int32_t dxfer_len, u_int32_t timeout)
127039212Sgibbs{
127139212Sgibbs	csio->ccb_h.func_code = XPT_CONT_TARGET_IO;
127239212Sgibbs	csio->ccb_h.flags = flags;
1273255915Snwhitehorn	csio->ccb_h.xflags = 0;
127439212Sgibbs	csio->ccb_h.retry_count = retries;
127539212Sgibbs	csio->ccb_h.cbfcnp = cbfcnp;
127639212Sgibbs	csio->ccb_h.timeout = timeout;
127739212Sgibbs	csio->data_ptr = data_ptr;
127839212Sgibbs	csio->dxfer_len = dxfer_len;
127939212Sgibbs	csio->scsi_status = scsi_status;
128039212Sgibbs	csio->tag_action = tag_action;
128139212Sgibbs	csio->tag_id = tag_id;
128239212Sgibbs	csio->init_id = init_id;
128339212Sgibbs}
128439212Sgibbs
1285195534Sscottlstatic __inline void
1286195534Sscottlcam_fill_ataio(struct ccb_ataio *ataio, u_int32_t retries,
1287195534Sscottl	      void (*cbfcnp)(struct cam_periph *, union ccb *),
1288195534Sscottl	      u_int32_t flags, u_int tag_action,
1289195534Sscottl	      u_int8_t *data_ptr, u_int32_t dxfer_len,
1290195534Sscottl	      u_int32_t timeout)
1291195534Sscottl{
1292195534Sscottl	ataio->ccb_h.func_code = XPT_ATA_IO;
1293195534Sscottl	ataio->ccb_h.flags = flags;
1294195534Sscottl	ataio->ccb_h.retry_count = retries;
1295195534Sscottl	ataio->ccb_h.cbfcnp = cbfcnp;
1296195534Sscottl	ataio->ccb_h.timeout = timeout;
1297195534Sscottl	ataio->data_ptr = data_ptr;
1298195534Sscottl	ataio->dxfer_len = dxfer_len;
1299195534Sscottl	ataio->tag_action = tag_action;
1300195534Sscottl}
1301195534Sscottl
1302216088Skenstatic __inline void
1303216088Skencam_fill_smpio(struct ccb_smpio *smpio, uint32_t retries,
1304216088Sken	       void (*cbfcnp)(struct cam_periph *, union ccb *), uint32_t flags,
1305216088Sken	       uint8_t *smp_request, int smp_request_len,
1306216088Sken	       uint8_t *smp_response, int smp_response_len,
1307216088Sken	       uint32_t timeout)
1308216088Sken{
1309216088Sken#ifdef _KERNEL
1310216088Sken	KASSERT((flags & CAM_DIR_MASK) == CAM_DIR_BOTH,
1311216088Sken		("direction != CAM_DIR_BOTH"));
1312216088Sken	KASSERT((smp_request != NULL) && (smp_response != NULL),
1313216088Sken		("need valid request and response buffers"));
1314216088Sken	KASSERT((smp_request_len != 0) && (smp_response_len != 0),
1315216088Sken		("need non-zero request and response lengths"));
1316216088Sken#endif /*_KERNEL*/
1317216088Sken	smpio->ccb_h.func_code = XPT_SMP_IO;
1318216088Sken	smpio->ccb_h.flags = flags;
1319216088Sken	smpio->ccb_h.retry_count = retries;
1320216088Sken	smpio->ccb_h.cbfcnp = cbfcnp;
1321216088Sken	smpio->ccb_h.timeout = timeout;
1322216088Sken	smpio->smp_request = smp_request;
1323216088Sken	smpio->smp_request_len = smp_request_len;
1324216088Sken	smpio->smp_response = smp_response;
1325216088Sken	smpio->smp_response_len = smp_response_len;
1326216088Sken}
1327216088Sken
1328252382Sscottlstatic __inline void
1329252382Sscottlcam_set_ccbstatus(union ccb *ccb, cam_status status)
1330252382Sscottl{
1331252382Sscottl	ccb->ccb_h.status &= ~CAM_STATUS_MASK;
1332252382Sscottl	ccb->ccb_h.status |= status;
1333252382Sscottl}
1334252382Sscottl
1335252382Sscottlstatic __inline cam_status
1336252382Sscottlcam_ccb_status(union ccb *ccb)
1337252382Sscottl{
1338252684Sjkim	return ((cam_status)(ccb->ccb_h.status & CAM_STATUS_MASK));
1339252382Sscottl}
1340252382Sscottl
1341116350Snjlvoid cam_calc_geometry(struct ccb_calc_geometry *ccg, int extended);
1342116350Snjl
134339212Sgibbs__END_DECLS
134439212Sgibbs
134539212Sgibbs#endif /* _CAM_CAM_CCB_H */
1346