xref: /illumos-gate/usr/src/uts/common/sys/fibre-channel/ulp/fcp_util.h (revision 2983dda76a6d296fdb560c88114fe41caad1b84f)
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 
26 #ifndef	_FCP_UTIL_H
27 #define	_FCP_UTIL_H
28 
29 
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/types.h>
36 
37 
38 #define	FCP_TGT_INQUIRY		0x01
39 #define	FCP_TGT_CREATE		0x02
40 #define	FCP_TGT_DELETE		0x04
41 #define	FCP_TGT_SEND_SCSI	0x08
42 #define	FCP_STATE_COUNT		0x10
43 #define	FCP_GET_TARGET_MAPPINGS	0x11
44 
45 struct	fcp_ioctl {
46 	minor_t		fp_minor;
47 	uint32_t	listlen;
48 	caddr_t		list;
49 };
50 
51 struct	device_data {
52 	la_wwn_t	dev_pwwn;
53 	int		dev_status;
54 	int		dev_lun_cnt;
55 	uchar_t		dev0_type;
56 };
57 
58 struct fcp_scsi_cmd {
59 	uint32_t	scsi_fc_port_num;
60 	la_wwn_t	scsi_fc_pwwn;
61 	uint32_t	scsi_fc_status;
62 	uint32_t	scsi_fc_rspcode;
63 	uchar_t		scsi_pkt_state;
64 	uchar_t		scsi_pkt_action;
65 	uint32_t	scsi_pkt_reason;
66 	uint64_t	scsi_lun;
67 	uint32_t	scsi_flags;
68 	uint32_t	scsi_timeout;
69 	caddr_t		scsi_cdbbufaddr;
70 	uint32_t	scsi_cdblen;
71 	caddr_t		scsi_bufaddr;
72 	uint32_t	scsi_buflen;
73 	int32_t		scsi_bufresid;
74 	uint32_t	scsi_bufstatus;
75 	caddr_t		scsi_rqbufaddr;
76 	uint32_t	scsi_rqlen;
77 	int32_t		scsi_rqresid;
78 };
79 
80 typedef struct fc_hba_mapping_entry {
81     char			targetDriver[MAXPATHLEN];
82     uint32_t			d_id;
83     uint32_t			busNumber;
84     uint32_t			targetNumber;
85     uint32_t			osLUN;
86     uint64_t			samLUN;
87     la_wwn_t			NodeWWN;
88     la_wwn_t			PortWWN;
89     uint8_t			guid[256];
90 } fc_hba_mapping_entry_t;
91 
92 #define	FC_HBA_TARGET_MAPPINGS_VERSION		1
93 typedef struct fc_hba_target_mappings {
94     uint32_t			version;
95     uint32_t			numLuns;
96     uint64_t			reserved;
97     fc_hba_mapping_entry_t	entries[1];
98 } fc_hba_target_mappings_t;
99 
100 /*
101  * flags for scsi_flags field of fcp_scsi_cmd structure
102  */
103 #define	FCP_SCSI_READ	0x0001	/* get data from device */
104 
105 
106 #if defined(_SYSCALL32)
107 /*
108  * 32 bit variant of fcp_ioctl and fcp_scsi_cmd
109  * used only in the driver.
110  */
111 
112 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
113 #pragma pack(4)
114 #endif
115 
116 struct	fcp32_ioctl {
117 	minor_t		fp_minor;
118 	uint32_t	listlen;
119 	caddr32_t	list;
120 };
121 
122 struct fcp32_scsi_cmd {
123 	uint32_t	scsi_fc_port_num;
124 	la_wwn_t	scsi_fc_pwwn;
125 	uint32_t	scsi_fc_status;
126 	uint32_t	scsi_fc_rspcode;
127 	uchar_t		scsi_pkt_state;
128 	uchar_t		scsi_pkt_action;
129 	uint32_t	scsi_pkt_reason;
130 	uint64_t	scsi_lun;
131 	uint32_t	scsi_flags;
132 	uint32_t	scsi_timeout;
133 	caddr32_t	scsi_cdbbufaddr;
134 	uint32_t	scsi_cdblen;
135 	caddr32_t	scsi_bufaddr;
136 	uint32_t	scsi_buflen;
137 	int32_t		scsi_bufresid;
138 	uint32_t	scsi_bufstatus;
139 	caddr32_t	scsi_rqbufaddr;
140 	uint32_t	scsi_rqlen;
141 	int32_t		scsi_rqresid;
142 };
143 
144 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
145 #pragma pack()
146 #endif
147 
148 #define	FCP32_SCSI_CMD_TO_FCP_SCSI_CMD(cmd32, cmd)			\
149 	(cmd)->scsi_fc_port_num	= (cmd32)->scsi_fc_port_num;		\
150 	bcopy(&((cmd32)->scsi_fc_pwwn), &((cmd)->scsi_fc_pwwn),		\
151 			sizeof ((cmd)->scsi_fc_pwwn));			\
152 	(cmd)->scsi_fc_status	= (cmd32)->scsi_fc_status;		\
153 	(cmd)->scsi_fc_rspcode	= (cmd32)->scsi_fc_rspcode;		\
154 	(cmd)->scsi_pkt_state	= (cmd32)->scsi_pkt_state;		\
155 	(cmd)->scsi_pkt_action	= (cmd32)->scsi_pkt_action;		\
156 	(cmd)->scsi_pkt_reason	= (cmd32)->scsi_pkt_reason;		\
157 	(cmd)->scsi_lun		= (cmd32)->scsi_lun;			\
158 	(cmd)->scsi_flags	= (cmd32)->scsi_flags;			\
159 	(cmd)->scsi_timeout	= (cmd32)->scsi_timeout;		\
160 	(cmd)->scsi_cdbbufaddr	= (caddr_t)(long)(cmd32)->scsi_cdbbufaddr; \
161 	(cmd)->scsi_cdblen	= (cmd32)->scsi_cdblen;			\
162 	(cmd)->scsi_bufaddr	= (caddr_t)(long)(cmd32)->scsi_bufaddr;	\
163 	(cmd)->scsi_buflen	= (cmd32)->scsi_buflen;			\
164 	(cmd)->scsi_bufresid	= (cmd32)->scsi_bufresid;		\
165 	(cmd)->scsi_bufstatus	= (cmd32)->scsi_bufstatus;		\
166 	(cmd)->scsi_rqbufaddr	= (caddr_t)(long)(cmd32)->scsi_rqbufaddr; \
167 	(cmd)->scsi_rqlen	= (cmd32)->scsi_rqlen;			\
168 	(cmd)->scsi_rqresid	= (cmd32)->scsi_rqresid;
169 
170 #define	FCP_SCSI_CMD_TO_FCP32_SCSI_CMD(cmd, cmd32)			\
171 	(cmd32)->scsi_fc_port_num = (cmd)->scsi_fc_port_num;		\
172 	bcopy(&((cmd)->scsi_fc_pwwn), &((cmd32)->scsi_fc_pwwn),		\
173 			sizeof ((cmd32)->scsi_fc_pwwn));		\
174 	(cmd32)->scsi_fc_status	= (cmd)->scsi_fc_status;		\
175 	(cmd32)->scsi_fc_rspcode = (cmd)->scsi_fc_rspcode;		\
176 	(cmd32)->scsi_pkt_state	= (cmd)->scsi_pkt_state;		\
177 	(cmd32)->scsi_pkt_action = (cmd)->scsi_pkt_action;		\
178 	(cmd32)->scsi_pkt_reason = (cmd)->scsi_pkt_reason;		\
179 	(cmd32)->scsi_lun	= (cmd)->scsi_lun;			\
180 	(cmd32)->scsi_flags	= (cmd)->scsi_flags;			\
181 	(cmd32)->scsi_timeout	= (cmd)->scsi_timeout;			\
182 	(cmd32)->scsi_cdbbufaddr = (caddr32_t)(long)(cmd)->scsi_cdbbufaddr; \
183 	(cmd32)->scsi_cdblen	= (cmd)->scsi_cdblen;			\
184 	(cmd32)->scsi_bufaddr	= (caddr32_t)(long)(cmd)->scsi_bufaddr;	\
185 	(cmd32)->scsi_buflen	= (cmd)->scsi_buflen;			\
186 	(cmd32)->scsi_bufresid	= (cmd)->scsi_bufresid;			\
187 	(cmd32)->scsi_bufstatus	= (cmd)->scsi_bufstatus;		\
188 	(cmd32)->scsi_rqbufaddr	= (caddr32_t)(long)(cmd)->scsi_rqbufaddr; \
189 	(cmd32)->scsi_rqlen	= (cmd)->scsi_rqlen;			\
190 	(cmd32)->scsi_rqresid	= (cmd)->scsi_rqresid;
191 
192 #endif /* _SYSCALL32 */
193 
194 #if !defined(__lint)
195 _NOTE(SCHEME_PROTECTS_DATA("Unshared Data", device_data))
196 _NOTE(SCHEME_PROTECTS_DATA("Unshared Data", fcp_scsi_cmd))
197 #endif /* __lint */
198 
199 #ifdef	__cplusplus
200 }
201 #endif
202 
203 #endif	/* _FCP_UTIL_H */
204