1*fcf3ce44SJohn Forte /*
2*fcf3ce44SJohn Forte  * CDDL HEADER START
3*fcf3ce44SJohn Forte  *
4*fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5*fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6*fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7*fcf3ce44SJohn Forte  *
8*fcf3ce44SJohn Forte  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*fcf3ce44SJohn Forte  * or http://www.opensolaris.org/os/licensing.
10*fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11*fcf3ce44SJohn Forte  * and limitations under the License.
12*fcf3ce44SJohn Forte  *
13*fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14*fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16*fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17*fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18*fcf3ce44SJohn Forte  *
19*fcf3ce44SJohn Forte  * CDDL HEADER END
20*fcf3ce44SJohn Forte  */
21*fcf3ce44SJohn Forte /*
22*fcf3ce44SJohn Forte  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*fcf3ce44SJohn Forte  * Use is subject to license terms.
24*fcf3ce44SJohn Forte  */
25*fcf3ce44SJohn Forte 
26*fcf3ce44SJohn Forte #ifndef	_FCP_UTIL_H
27*fcf3ce44SJohn Forte #define	_FCP_UTIL_H
28*fcf3ce44SJohn Forte 
29*fcf3ce44SJohn Forte 
30*fcf3ce44SJohn Forte 
31*fcf3ce44SJohn Forte #ifdef	__cplusplus
32*fcf3ce44SJohn Forte extern "C" {
33*fcf3ce44SJohn Forte #endif
34*fcf3ce44SJohn Forte 
35*fcf3ce44SJohn Forte #include <sys/types.h>
36*fcf3ce44SJohn Forte 
37*fcf3ce44SJohn Forte 
38*fcf3ce44SJohn Forte #define	FCP_TGT_INQUIRY		0x01
39*fcf3ce44SJohn Forte #define	FCP_TGT_CREATE		0x02
40*fcf3ce44SJohn Forte #define	FCP_TGT_DELETE		0x04
41*fcf3ce44SJohn Forte #define	FCP_TGT_SEND_SCSI	0x08
42*fcf3ce44SJohn Forte #define	FCP_STATE_COUNT		0x10
43*fcf3ce44SJohn Forte #define	FCP_GET_TARGET_MAPPINGS	0x11
44*fcf3ce44SJohn Forte 
45*fcf3ce44SJohn Forte struct	fcp_ioctl {
46*fcf3ce44SJohn Forte 	minor_t		fp_minor;
47*fcf3ce44SJohn Forte 	uint32_t	listlen;
48*fcf3ce44SJohn Forte 	caddr_t		list;
49*fcf3ce44SJohn Forte };
50*fcf3ce44SJohn Forte 
51*fcf3ce44SJohn Forte struct	device_data {
52*fcf3ce44SJohn Forte 	la_wwn_t	dev_pwwn;
53*fcf3ce44SJohn Forte 	int		dev_status;
54*fcf3ce44SJohn Forte 	int		dev_lun_cnt;
55*fcf3ce44SJohn Forte 	uchar_t		dev0_type;
56*fcf3ce44SJohn Forte };
57*fcf3ce44SJohn Forte 
58*fcf3ce44SJohn Forte struct fcp_scsi_cmd {
59*fcf3ce44SJohn Forte 	uint32_t	scsi_fc_port_num;
60*fcf3ce44SJohn Forte 	la_wwn_t	scsi_fc_pwwn;
61*fcf3ce44SJohn Forte 	uint32_t	scsi_fc_status;
62*fcf3ce44SJohn Forte 	uint32_t	scsi_fc_rspcode;
63*fcf3ce44SJohn Forte 	uchar_t		scsi_pkt_state;
64*fcf3ce44SJohn Forte 	uchar_t		scsi_pkt_action;
65*fcf3ce44SJohn Forte 	uint32_t	scsi_pkt_reason;
66*fcf3ce44SJohn Forte 	uint64_t	scsi_lun;
67*fcf3ce44SJohn Forte 	uint32_t	scsi_flags;
68*fcf3ce44SJohn Forte 	uint32_t	scsi_timeout;
69*fcf3ce44SJohn Forte 	caddr_t		scsi_cdbbufaddr;
70*fcf3ce44SJohn Forte 	uint32_t	scsi_cdblen;
71*fcf3ce44SJohn Forte 	caddr_t		scsi_bufaddr;
72*fcf3ce44SJohn Forte 	uint32_t	scsi_buflen;
73*fcf3ce44SJohn Forte 	int32_t		scsi_bufresid;
74*fcf3ce44SJohn Forte 	uint32_t	scsi_bufstatus;
75*fcf3ce44SJohn Forte 	caddr_t		scsi_rqbufaddr;
76*fcf3ce44SJohn Forte 	uint32_t	scsi_rqlen;
77*fcf3ce44SJohn Forte 	int32_t		scsi_rqresid;
78*fcf3ce44SJohn Forte };
79*fcf3ce44SJohn Forte 
80*fcf3ce44SJohn Forte typedef struct fc_hba_mapping_entry {
81*fcf3ce44SJohn Forte     char			targetDriver[MAXPATHLEN];
82*fcf3ce44SJohn Forte     uint32_t			d_id;
83*fcf3ce44SJohn Forte     uint32_t			busNumber;
84*fcf3ce44SJohn Forte     uint32_t			targetNumber;
85*fcf3ce44SJohn Forte     uint32_t			osLUN;
86*fcf3ce44SJohn Forte     uint64_t			samLUN;
87*fcf3ce44SJohn Forte     la_wwn_t			NodeWWN;
88*fcf3ce44SJohn Forte     la_wwn_t			PortWWN;
89*fcf3ce44SJohn Forte     uint8_t			guid[256];
90*fcf3ce44SJohn Forte } fc_hba_mapping_entry_t;
91*fcf3ce44SJohn Forte 
92*fcf3ce44SJohn Forte #define	FC_HBA_TARGET_MAPPINGS_VERSION		1
93*fcf3ce44SJohn Forte typedef struct fc_hba_target_mappings {
94*fcf3ce44SJohn Forte     uint32_t			version;
95*fcf3ce44SJohn Forte     uint32_t			numLuns;
96*fcf3ce44SJohn Forte     uint64_t			reserved;
97*fcf3ce44SJohn Forte     fc_hba_mapping_entry_t	entries[1];
98*fcf3ce44SJohn Forte } fc_hba_target_mappings_t;
99*fcf3ce44SJohn Forte 
100*fcf3ce44SJohn Forte /*
101*fcf3ce44SJohn Forte  * flags for scsi_flags field of fcp_scsi_cmd structure
102*fcf3ce44SJohn Forte  */
103*fcf3ce44SJohn Forte #define	FCP_SCSI_READ	0x0001	/* get data from device */
104*fcf3ce44SJohn Forte 
105*fcf3ce44SJohn Forte 
106*fcf3ce44SJohn Forte #if defined(_SYSCALL32)
107*fcf3ce44SJohn Forte /*
108*fcf3ce44SJohn Forte  * 32 bit variant of fcp_ioctl and fcp_scsi_cmd
109*fcf3ce44SJohn Forte  * used only in the driver.
110*fcf3ce44SJohn Forte  */
111*fcf3ce44SJohn Forte 
112*fcf3ce44SJohn Forte #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
113*fcf3ce44SJohn Forte #pragma pack(4)
114*fcf3ce44SJohn Forte #endif
115*fcf3ce44SJohn Forte 
116*fcf3ce44SJohn Forte struct	fcp32_ioctl {
117*fcf3ce44SJohn Forte 	minor_t		fp_minor;
118*fcf3ce44SJohn Forte 	uint32_t	listlen;
119*fcf3ce44SJohn Forte 	caddr32_t	list;
120*fcf3ce44SJohn Forte };
121*fcf3ce44SJohn Forte 
122*fcf3ce44SJohn Forte struct fcp32_scsi_cmd {
123*fcf3ce44SJohn Forte 	uint32_t	scsi_fc_port_num;
124*fcf3ce44SJohn Forte 	la_wwn_t	scsi_fc_pwwn;
125*fcf3ce44SJohn Forte 	uint32_t	scsi_fc_status;
126*fcf3ce44SJohn Forte 	uint32_t	scsi_fc_rspcode;
127*fcf3ce44SJohn Forte 	uchar_t		scsi_pkt_state;
128*fcf3ce44SJohn Forte 	uchar_t		scsi_pkt_action;
129*fcf3ce44SJohn Forte 	uint32_t	scsi_pkt_reason;
130*fcf3ce44SJohn Forte 	uint64_t	scsi_lun;
131*fcf3ce44SJohn Forte 	uint32_t	scsi_flags;
132*fcf3ce44SJohn Forte 	uint32_t	scsi_timeout;
133*fcf3ce44SJohn Forte 	caddr32_t	scsi_cdbbufaddr;
134*fcf3ce44SJohn Forte 	uint32_t	scsi_cdblen;
135*fcf3ce44SJohn Forte 	caddr32_t	scsi_bufaddr;
136*fcf3ce44SJohn Forte 	uint32_t	scsi_buflen;
137*fcf3ce44SJohn Forte 	int32_t		scsi_bufresid;
138*fcf3ce44SJohn Forte 	uint32_t	scsi_bufstatus;
139*fcf3ce44SJohn Forte 	caddr32_t	scsi_rqbufaddr;
140*fcf3ce44SJohn Forte 	uint32_t	scsi_rqlen;
141*fcf3ce44SJohn Forte 	int32_t		scsi_rqresid;
142*fcf3ce44SJohn Forte };
143*fcf3ce44SJohn Forte 
144*fcf3ce44SJohn Forte #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
145*fcf3ce44SJohn Forte #pragma pack()
146*fcf3ce44SJohn Forte #endif
147*fcf3ce44SJohn Forte 
148*fcf3ce44SJohn Forte #define	FCP32_SCSI_CMD_TO_FCP_SCSI_CMD(cmd32, cmd)			\
149*fcf3ce44SJohn Forte 	(cmd)->scsi_fc_port_num	= (cmd32)->scsi_fc_port_num;		\
150*fcf3ce44SJohn Forte 	bcopy(&((cmd32)->scsi_fc_pwwn), &((cmd)->scsi_fc_pwwn),		\
151*fcf3ce44SJohn Forte 			sizeof ((cmd)->scsi_fc_pwwn));			\
152*fcf3ce44SJohn Forte 	(cmd)->scsi_fc_status	= (cmd32)->scsi_fc_status;		\
153*fcf3ce44SJohn Forte 	(cmd)->scsi_fc_rspcode	= (cmd32)->scsi_fc_rspcode;		\
154*fcf3ce44SJohn Forte 	(cmd)->scsi_pkt_state	= (cmd32)->scsi_pkt_state;		\
155*fcf3ce44SJohn Forte 	(cmd)->scsi_pkt_action	= (cmd32)->scsi_pkt_action;		\
156*fcf3ce44SJohn Forte 	(cmd)->scsi_pkt_reason	= (cmd32)->scsi_pkt_reason;		\
157*fcf3ce44SJohn Forte 	(cmd)->scsi_lun		= (cmd32)->scsi_lun;			\
158*fcf3ce44SJohn Forte 	(cmd)->scsi_flags	= (cmd32)->scsi_flags;			\
159*fcf3ce44SJohn Forte 	(cmd)->scsi_timeout	= (cmd32)->scsi_timeout;		\
160*fcf3ce44SJohn Forte 	(cmd)->scsi_cdbbufaddr	= (caddr_t)(long)(cmd32)->scsi_cdbbufaddr; \
161*fcf3ce44SJohn Forte 	(cmd)->scsi_cdblen	= (cmd32)->scsi_cdblen;			\
162*fcf3ce44SJohn Forte 	(cmd)->scsi_bufaddr	= (caddr_t)(long)(cmd32)->scsi_bufaddr;	\
163*fcf3ce44SJohn Forte 	(cmd)->scsi_buflen	= (cmd32)->scsi_buflen;			\
164*fcf3ce44SJohn Forte 	(cmd)->scsi_bufresid	= (cmd32)->scsi_bufresid;		\
165*fcf3ce44SJohn Forte 	(cmd)->scsi_bufstatus	= (cmd32)->scsi_bufstatus;		\
166*fcf3ce44SJohn Forte 	(cmd)->scsi_rqbufaddr	= (caddr_t)(long)(cmd32)->scsi_rqbufaddr; \
167*fcf3ce44SJohn Forte 	(cmd)->scsi_rqlen	= (cmd32)->scsi_rqlen;			\
168*fcf3ce44SJohn Forte 	(cmd)->scsi_rqresid	= (cmd32)->scsi_rqresid;
169*fcf3ce44SJohn Forte 
170*fcf3ce44SJohn Forte #define	FCP_SCSI_CMD_TO_FCP32_SCSI_CMD(cmd, cmd32)			\
171*fcf3ce44SJohn Forte 	(cmd32)->scsi_fc_port_num = (cmd)->scsi_fc_port_num;		\
172*fcf3ce44SJohn Forte 	bcopy(&((cmd)->scsi_fc_pwwn), &((cmd32)->scsi_fc_pwwn),		\
173*fcf3ce44SJohn Forte 			sizeof ((cmd32)->scsi_fc_pwwn));		\
174*fcf3ce44SJohn Forte 	(cmd32)->scsi_fc_status	= (cmd)->scsi_fc_status;		\
175*fcf3ce44SJohn Forte 	(cmd32)->scsi_fc_rspcode = (cmd)->scsi_fc_rspcode;		\
176*fcf3ce44SJohn Forte 	(cmd32)->scsi_pkt_state	= (cmd)->scsi_pkt_state;		\
177*fcf3ce44SJohn Forte 	(cmd32)->scsi_pkt_action = (cmd)->scsi_pkt_action;		\
178*fcf3ce44SJohn Forte 	(cmd32)->scsi_pkt_reason = (cmd)->scsi_pkt_reason;		\
179*fcf3ce44SJohn Forte 	(cmd32)->scsi_lun	= (cmd)->scsi_lun;			\
180*fcf3ce44SJohn Forte 	(cmd32)->scsi_flags	= (cmd)->scsi_flags;			\
181*fcf3ce44SJohn Forte 	(cmd32)->scsi_timeout	= (cmd)->scsi_timeout;			\
182*fcf3ce44SJohn Forte 	(cmd32)->scsi_cdbbufaddr = (caddr32_t)(long)(cmd)->scsi_cdbbufaddr; \
183*fcf3ce44SJohn Forte 	(cmd32)->scsi_cdblen	= (cmd)->scsi_cdblen;			\
184*fcf3ce44SJohn Forte 	(cmd32)->scsi_bufaddr	= (caddr32_t)(long)(cmd)->scsi_bufaddr;	\
185*fcf3ce44SJohn Forte 	(cmd32)->scsi_buflen	= (cmd)->scsi_buflen;			\
186*fcf3ce44SJohn Forte 	(cmd32)->scsi_bufresid	= (cmd)->scsi_bufresid;			\
187*fcf3ce44SJohn Forte 	(cmd32)->scsi_bufstatus	= (cmd)->scsi_bufstatus;		\
188*fcf3ce44SJohn Forte 	(cmd32)->scsi_rqbufaddr	= (caddr32_t)(long)(cmd)->scsi_rqbufaddr; \
189*fcf3ce44SJohn Forte 	(cmd32)->scsi_rqlen	= (cmd)->scsi_rqlen;			\
190*fcf3ce44SJohn Forte 	(cmd32)->scsi_rqresid	= (cmd)->scsi_rqresid;
191*fcf3ce44SJohn Forte 
192*fcf3ce44SJohn Forte #endif /* _SYSCALL32 */
193*fcf3ce44SJohn Forte 
194*fcf3ce44SJohn Forte #if !defined(__lint)
195*fcf3ce44SJohn Forte _NOTE(SCHEME_PROTECTS_DATA("Unshared Data", device_data))
196*fcf3ce44SJohn Forte _NOTE(SCHEME_PROTECTS_DATA("Unshared Data", fcp_scsi_cmd))
197*fcf3ce44SJohn Forte #endif /* __lint */
198*fcf3ce44SJohn Forte 
199*fcf3ce44SJohn Forte #ifdef	__cplusplus
200*fcf3ce44SJohn Forte }
201*fcf3ce44SJohn Forte #endif
202*fcf3ce44SJohn Forte 
203*fcf3ce44SJohn Forte #endif	/* _FCP_UTIL_H */