xref: /illumos-gate/usr/src/uts/sun/sys/scsi/adapters/fascmd.h (revision 602ca9ea8f9ce0933f0944601cc5d230e91a950d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 #ifndef	_SYS_SCSI_ADAPTERS_FASCMD_H
26 #define	_SYS_SCSI_ADAPTERS_FASCMD_H
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #include <sys/note.h>
31 #include <sys/isa_defs.h>
32 #include <sys/scsi/scsi_types.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * The transport layer deals with things in terms of the following structure.
40  * Note	that the target	driver's view of things	is the scsi_pkt	that is
41  * enfolded as the first element of the	following structure.
42  *
43  * the preferred the cdb size is 12. fas is a scsi2 HBA driver and
44  * rarely needs 16 byte cdb's
45  */
46 
47 /*
48  * preferred pkt_private length in 64-bit quantities
49  */
50 #ifdef	_LP64
51 #define	PKT_PRIV_SIZE	2
52 #define	PKT_PRIV_LEN	16	/* in bytes */
53 #else /* _ILP32 */
54 #define	PKT_PRIV_SIZE	1
55 #define	PKT_PRIV_LEN	8	/* in bytes */
56 #endif
57 
58 
59 #define	PKT2CMD(pkt)		((struct fas_cmd *)(pkt)->pkt_ha_private)
60 #define	CMD2PKT(sp)		((sp)->cmd_pkt)
61 
62 #define	EXTCMD_SIZE		(sizeof (struct fas_cmd) + scsi_pkt_size())
63 #define	EXTCMDS_STATUS_SIZE	(sizeof (struct scsi_arq_status))
64 
65 struct fas_cmd {
66 	struct scsi_pkt		*cmd_pkt;	/* the generic packet itself */
67 	struct fas_cmd		*cmd_forw;	/* ready fifo que link */
68 	uchar_t			*cmd_cdbp;	/* active command pointer */
69 
70 	uint32_t		cmd_data_count;	/* aggregate data count */
71 	uint32_t		cmd_cur_addr;	/* current dma address */
72 
73 	ushort_t		cmd_qfull_retries;
74 
75 	ushort_t		cmd_nwin;	/* number of windows */
76 	ushort_t		cmd_cur_win;	/* current window */
77 
78 	ushort_t		cmd_saved_win;	/* saved window */
79 	uint32_t		cmd_saved_data_count; /* saved aggr. count */
80 	uint32_t		cmd_saved_cur_addr; /* saved virt address */
81 	int			cmd_pkt_flags;	/* copy	of pkt_flags */
82 
83 	ddi_dma_handle_t	cmd_dmahandle;	/* dma handle */
84 	ddi_dma_cookie_t	cmd_dmacookie;	/* current dma cookie */
85 	uint32_t		cmd_dmacount;	/* total xfer count */
86 
87 	uchar_t			cmd_cdb[CDB_SIZE]; /* 12 byte cdb */
88 	uint_t			cmd_flags;	/* private flags */
89 	struct scsi_arq_status	cmd_scb;
90 	uint_t			cmd_scblen;	/* length of scb */
91 	uchar_t			cmd_slot;
92 	uchar_t			cmd_age;	/* cmd age (tagged queing) */
93 	uint_t			cmd_cdblen;	/* length of cdb */
94 	uint64_t		cmd_pkt_private[PKT_PRIV_SIZE];
95 	uint_t			cmd_privlen;	/* length of tgt private */
96 	uchar_t			cmd_tag[2];	/* command tag */
97 	uchar_t			cmd_actual_cdblen; /* length of	cdb */
98 };
99 
100 _NOTE(SCHEME_PROTECTS_DATA("unique per pkt", fas_cmd))
101 
102 /*
103  * private data	for arq	pkt
104  */
105 struct arq_private_data	{
106 	struct buf	*arq_save_bp;
107 	struct fas_cmd	*arq_save_sp;
108 };
109 
110 /*
111  * A note about	the cmd_cdb && cmd_scb structures:
112  *
113  *	If the command allocation requested exceeds the	size of	CDB_SIZE,
114  *	the cdb	will be	allocated outside this structure (via kmem_zalloc)
115  *	The same applies to cmd_scb.
116  */
117 
118 /*
119  * These are the defined flags for this	structure.
120  */
121 #define	CFLAG_CMDDISC		0x0001	/* cmd currently disconnected */
122 #define	CFLAG_WATCH		0x0002	/* watchdog time for this command */
123 #define	CFLAG_FINISHED		0x0004	/* command completed */
124 #define	CFLAG_CHKSEG		0x0008	/* check cmd_data within seg */
125 #define	CFLAG_COMPLETED		0x0010	/* completion routine called */
126 #define	CFLAG_PREPARED		0x0020	/* pkt has been	init'ed	*/
127 #define	CFLAG_IN_TRANSPORT	0x0040	/* in use by host adapter driver */
128 #define	CFLAG_RESTORE_PTRS	0x0080	/* implicit restore ptr on reconnect */
129 #define	CFLAG_TRANFLAG		0x00ff	/* covers transport part of flags */
130 #define	CFLAG_CMDPROXY		0x000100 /* cmd	is a 'proxy' command */
131 #define	CFLAG_CMDARQ		0x000200 /* cmd	is a 'rqsense' command */
132 #define	CFLAG_DMAVALID		0x000400 /* dma	mapping	valid */
133 #define	CFLAG_DMASEND		0x000800 /* data	is going 'out' */
134 #define	CFLAG_CMDIOPB		0x001000 /* this	is an 'iopb' packet */
135 #define	CFLAG_CDBEXTERN		0x002000 /* cdb	kmem_alloc'd */
136 #define	CFLAG_SCBEXTERN		0x004000 /* scb	kmem_alloc'd */
137 #define	CFLAG_FREE		0x008000 /* packet is on	free list */
138 #define	CFLAG_PRIVEXTERN	0x020000 /* target private kmem_alloc'd	*/
139 #define	CFLAG_DMA_PARTIAL	0x040000 /* partial xfer OK */
140 
141 #ifdef	__cplusplus
142 }
143 #endif
144 
145 #endif	/* _SYS_SCSI_ADAPTERS_FASCMD_H */
146