xref: /illumos-gate/usr/src/uts/common/sys/fc4/fc_transport.h (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_FC4_FC_TRANSPORT_H
28 #define	_SYS_FC4_FC_TRANSPORT_H
29 
30 #include <sys/fc4/fc.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * fc_devdata_t definitions
38  *
39  * See fc.h for TYPE field definitions
40  */
41 typedef int fc_devdata_t;
42 
43 /*
44  * fc_ioclass_t definitions.
45  */
46 typedef enum {
47 	FC_CLASS_OUTBOUND,
48 	FC_CLASS_INBOUND,
49 	FC_CLASS_SIMPLE,
50 	FC_CLASS_IO_WRITE,
51 	FC_CLASS_IO_READ,
52 	FC_CLASS_OFFLINE,
53 	FC_CLASS_UNSOLICITED
54 } fc_ioclass_t;
55 
56 /*
57  * This data structure is used by a Fiber Channel Adaptor driver client to
58  * request a Fiber Channel transaction.
59  */
60 
61 typedef struct fc_packet {
62 			/*
63 			 * identifies which FC device
64 			 *
65 			 * In our case it is a pointer to the
66 			 * port_status structure. This structure
67 			 * contains the physical port (0 or 1).
68 			 */
69 	void		*fc_pkt_cookie;	/* identifies which FC device */
70 
71 	void		(*fc_pkt_comp)(struct fc_packet *);
72 	void		*fc_pkt_private;
73 	int32_t		fc_pkt_flags;		/* flags */
74 	int32_t		fc_pkt_timeout;		/* Max time to complete */
75 	fc_ioclass_t	fc_pkt_io_class;	/* fc io class */
76 	fc_devdata_t	fc_pkt_io_devdata;	/* FC IO Device Data. */
77 	fc_dataseg_t	*fc_pkt_cmd;		/* Outbound packet */
78 	fc_dataseg_t	*fc_pkt_rsp;		/* Inbound  Packet */
79 	fc_dataseg_t	**fc_pkt_datap;		/* List of Data Packets */
80 
81 	/*
82 	 * SOC status from soc status field in Response que.
83 	 */
84 	unsigned int	fc_pkt_status;		/* SOC Status when complete */
85 	int		fc_pkt_statistics;	/* not used */
86 
87 	fc_frame_header_t	*fc_frame_cmd,	/* used for command */
88 				*fc_frame_resp;	/* used for response */
89 
90 	struct fc_packet	*fc_pkt_next,	/* Chain of FC packet reqs. */
91 				*fc_pkt_prev;
92 } fc_packet_t;
93 
94 /*
95  *	Fibre channel packet flags
96  */
97 #define	FCFLAG_NOINTR		1	/* run this command without intr */
98 #define	FCFLAG_COMPLETE		2	/* command has completed */
99 
100 /*
101  * fc_transport() return values
102  */
103 enum {
104 	FC_TRANSPORT_SUCCESS,		/* success */
105 	FC_TRANSPORT_FAILURE,		/* failure */
106 	FC_TRANSPORT_TIMEOUT,		/* timeout while polling */
107 	FC_TRANSPORT_QFULL,		/* queue full */
108 	FC_TRANSPORT_UNAVAIL		/* temp. unavailable, e.g., offline */
109 };
110 
111 
112 /*
113  * pkt_status return values
114  */
115 #define	FC_STATUS_OK			0
116 #define	FC_STATUS_P_RJT			2
117 #define	FC_STATUS_F_RJT			3
118 #define	FC_STATUS_P_BSY			4
119 #define	FC_STATUS_F_BSY			5
120 #define	FC_STATUS_ERR_OFFLINE		0x11
121 #define	FC_STATUS_TIMEOUT		0x12
122 #define	FC_STATUS_ERR_OVERRUN		0x13
123 #define	FC_STATUS_UNKNOWN_CQ_TYPE	0x20
124 #define	FC_STATUS_BAD_SEG_CNT		0x21
125 #define	FC_STATUS_MAX_XCHG_EXCEEDED	0x22
126 #define	FC_STATUS_BAD_XID		0x23
127 #define	FC_STATUS_XCHG_BUSY		0x24
128 #define	FC_STATUS_BAD_POOL_ID		0x25
129 #define	FC_STATUS_INSUFFICIENT_CQES	0x26
130 #define	FC_STATUS_ALLOC_FAIL		0x27
131 #define	FC_STATUS_BAD_SID		0x28
132 #define	FC_STATUS_NO_SEQ_INIT		0x29
133 #define	FC_STATUS_ERROR			0x80
134 #define	FC_STATUS_ONLINE_TIMEOUT	0x81
135 /*
136  * additional pseudo-status codes for login
137  */
138 #define	FC_STATUS_LOGIN_TIMEOUT		0x80000001u
139 #define	FC_STATUS_CQFULL		0x80000002u
140 #define	FC_STATUS_TRANSFAIL		0x80000003u
141 #define	FC_STATUS_RESETFAIL		0x80000004u
142 
143 /*
144  * fc_uc_register() return values
145  */
146 typedef void * fc_uc_cookie_t;
147 
148 /*
149  * fc_transport() iotype parameter
150  */
151 typedef enum {
152 	FC_TYPE_UNCATEGORIZED,
153 	FC_TYPE_DATA,
154 	FC_TYPE_UNSOL_CONTROL,
155 	FC_TYPE_SOLICITED_CONTROL,
156 	FC_TYPE_UNSOL_DATA,
157 	FC_TYPE_XFER_RDY,
158 	FC_TYPE_COMMAND,
159 	FC_TYPE_RESPONSE
160 } fc_iotype_t;
161 
162 
163 /*
164  * fc_transport() sleep parameter
165  */
166 typedef enum {
167 	FC_SLEEP,			/* sleep on queue full */
168 	FC_NOSLEEP			/* do not sleep on queue full */
169 } fc_sleep_t;
170 
171 
172 /*
173  * State changes related to the N-port interface communicated from below
174  */
175 typedef enum {
176 	FC_STATE_ONLINE,		/* port has gone online */
177 	FC_STATE_OFFLINE,		/* port has gone offline */
178 	FC_STATE_RESET			/* port reset, all cmds lost */
179 } fc_statec_t;
180 
181 typedef void * fc_statec_cookie_t;
182 
183 /*
184  * This structure is allocated by Fiber Channel Adaptor at INITCHILD time,
185  * and is  communicated to the child by ddi_set_driver_private().
186  * It defines the vectors by which the child obtains soc
187  * driver services, and all other information the child
188  * may need about its parent.
189  */
190 
191 typedef struct fc_transport {
192 	void			*fc_cookie;	/* Which FC dev. */
193 	ddi_dma_lim_t		*fc_dmalimp;	/* FC ddi_dma_lim_t ptr. */
194 	ddi_dma_attr_t		*fc_dma_attrp;	/* FC ddi_dma_attr_t ptr. */
195 	ddi_iblock_cookie_t	fc_iblock;	/* iblock for mutexes */
196 	kmutex_t		fc_mtx;		/* Locks for transport */
197 	kcondvar_t		fc_cv;
198 
199 	/*
200 	 * Transport a command across the interface.
201 	 */
202 	int		(*fc_transport)(
203 				struct fc_packet	*fc,
204 				fc_sleep_t		sleep);
205 
206 	/*
207 	 * Reset the transport.
208 	 */
209 	int		(*fc_reset)(
210 				struct fc_packet	*fc);
211 
212 	/*
213 	 * Allocate an fc_packet structure.
214 	 */
215 	fc_packet_t	*(*fc_pkt_alloc)(
216 				void			*cookie,
217 				fc_sleep_t		sleep);
218 
219 	/*
220 	 * Free an fc_packet structure.
221 	 */
222 	void		(*fc_pkt_free)(
223 				void			*cookie,
224 				struct fc_packet	*pkt);
225 
226 	/*
227 	 * Register a routine to handle state changes on the interface
228 	 *
229 	 * The arg parameter, along with an fc_statec_t parameter, will
230 	 * be passed to the callback routine on all state changes
231 	 * after initialization.
232 	 */
233 	fc_statec_cookie_t
234 			(*fc_statec_register)(
235 			void	*cookie,
236 			void	(*callback)(void *, fc_statec_t),
237 			void	*arg);
238 
239 	/*
240 	 * Unregister a routine to handle state changes
241 	 */
242 	void	(*fc_statec_unregister)(
243 			void	*cookie,
244 			fc_statec_cookie_t statec_cookie);
245 
246 	/*
247 	 * Run the interface in polling mode.  This allows interface
248 	 * state changes, etc. to be processed when system interrupts
249 	 * are disabled.  This is used mostly for error recovery.
250 	 * Too bad Fibre Channel doesn't have a common error policy for
251 	 * all protocols so that we could do error recovery at
252 	 * the lowest level instead of having kludges like this...
253 	 */
254 	void	(*fc_interface_poll)(
255 			void	*cookie);
256 
257 	/*
258 	 * Unsolicited Command Interface
259 	 *
260 	 * This interface operates with the presumption that the
261 	 * higher level driver (child) will process unsolicited
262 	 * commands that pertain to its protocol such as FCP or FCIP.
263 	 */
264 
265 	/*
266 	 * Register a callback to be called in the event of an
267 	 * unsolicited command received by the soc for this child.
268 	 * No information is passed regarding the event, just that
269 	 * one occurred.  The arg parameter to passed to the
270 	 * callback function as its parameter.
271 	 */
272 	fc_uc_cookie_t
273 			(*fc_uc_register)(
274 			void			*cookie,
275 			fc_devdata_t		devdata,
276 			void			(*callback)(void *),
277 			void			*arg);
278 
279 	/*
280 	 * Unregister a callback routine
281 	 */
282 	void	(*fc_uc_unregister)(
283 			void			*cookie,
284 			fc_uc_cookie_t		uc_cookie);
285 
286 	/*
287 	 * Return information about the unsolicited command
288 	 * event in pkt.  The pkt must be a fully allocated
289 	 * fc_packet structure, with a valid cmd dataseg
290 	 * pointer, in which the received cmd payload will
291 	 * be placed.  The length of the allocated dataseg should
292 	 * be greater than or equal to the length of the received
293 	 * command payload, otherwise the entire command cannot
294 	 * be copied into the data segment.  This function
295 	 * returns -1 in the event of an error, or the
296 	 * actual length of the received command payload.
297 	 */
298 	int	(*fc_uc_get_pkt)(
299 			void			*cookie,
300 			struct fc_packet	*pkt);
301 
302 } fc_transport_t;
303 
304 
305 #ifdef	__cplusplus
306 }
307 #endif
308 
309 #endif	/* !_SYS_FC4_FC_TRANSPORT_H */
310