xref: /titanic_41/usr/src/uts/common/sys/fibre-channel/ulp/fcpvar.h (revision 3fb517f786391b507780c78aabb8d98bfea9efe9)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_FCPVAR_H
27 #define	_FCPVAR_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include <sys/types.h>
34 
35 /*
36  * Maximum number of times FCP will re-issue a REPORTS_LUNS command if the
37  * device couldn't return all of them in the submitted buffer.
38  */
39 #define	FCP_MAX_REPORTLUNS_ATTEMPTS	2
40 /*
41  * Maximum number of LUNs supported.  This limit is enforced to accommodate
42  * certain HBAs.
43  */
44 #define	FCP_MAX_LUNS_SUPPORTED		65535
45 
46 /*
47  * Stuff to be defined in fc_ulpif.h FIXIT
48  */
49 #define	PORT_DEVICE_CREATE	0x40
50 #define	SCMD_REPORT_LUN		0xa0	/* SCSI cmd to report on LUNs */
51 #define	SCMD_INQUIRY_LWWN_SIZE	32	/* Max WWN size */
52 #define	SCMD_INQUIRY_PAGE83	0xF0	/* Internal opcode for page 0x83 */
53 #define	FC4_SCSI_FCP		0x08	/* our (SCSI) FC4 type number */
54 
55 #define	FCP_QUEUE_DELAY	(4)
56 #define	FCP_FAILED_DELAY	20
57 #define	FCP_RESET_DELAY		3	/* target reset delay of 3 secs */
58 #define	FCP_OFFLINE_DELAY	20	/* 20 seconds is 2*RA_TOV_els */
59 
60 /*
61  * Highest possible timeout value to indicate
62  * the watch thread to return the I/O
63  */
64 #define	FCP_INVALID_TIMEOUT	(0xFFFFFFFF)
65 
66 /*
67  * The max inquiry page 83 size as expected in the code today
68  * is 0xf0 bytes. Defining a constant to make it easy incase
69  * this needs to be changed at a later time.
70  */
71 #define	SCMD_MAX_INQUIRY_PAGE83_SIZE	0xF0
72 /*
73  * Events generated for Target drivers; "SUNW,sf:" prefix
74  * is a legacy fcal stuff hardcoded into ssd via the use of
75  * FCAL_INSERT_EVENT defined in an fcal header file; We
76  * just need to continue to use this.
77  */
78 #define	FCAL_INSERT_EVENT	"SUNW,sf:DEVICE-INSERTION.1"
79 #define	FCAL_REMOVE_EVENT	"SUNW,sf:DEVICE-REMOVAL.1"
80 
81 /*
82  * for debug trace
83  */
84 #define	FCP_STACK_DEPTH	14
85 
86 
87 /*
88  * All the stuff above needs to move intp appropriate header files.
89  */
90 
91 #define	FCP_NUM_HASH			128
92 
93 #define	FCP_HASH(x)			((x[0] + x[1] + x[2] + x[3] +\
94 					x[4] + x[5] + x[6] + x[7]) & \
95 					(FCP_NUM_HASH-1))
96 
97 #define	FCP_STATEC_MASK			(FC_STATE_OFFLINE | FC_STATE_ONLINE |\
98 					FC_STATE_LOOP | FC_STATE_NAMESERVICE |\
99 					FC_STATE_RESET |\
100 					FC_STATE_RESET_REQUESTED |\
101 					FC_STATE_LIP | FC_STATE_DEVICE_CHANGE)
102 
103 #define	PKT_PRIV_SIZE			2
104 
105 #ifdef	KSTATS_CODE
106 /*
107  * fcp_stats : Statistics provided for fcp.
108  */
109 struct fcp_stats {
110 	uint_t	version;		/* version of this struct */
111 	uint_t	lip_count;		/* lips forced by fcp */
112 	uint_t	link_reset_count;	/* lip failures, ie, no ONLINE */
113 					/* response after forcing lip */
114 	uint_t	ncmds;			/* outstanding commands */
115 	uint_t	throttle_limit;		/* current throttle limit */
116 	char	drvr_name[MAXNAMELEN];	/* Name of driver, NULL term. */
117 };
118 #endif
119 
120 /*
121  * Structure fcp_port
122  * --------------------
123  *
124  * This structure is the FCP representation of an N_Port on a local FC HBA card.
125  * This is the master structure off of which all the others will be hanging at
126  * some point and is the Solaris per-instance soft-state structure.
127  */
128 typedef struct fcp_port {
129 	/*
130 	 * This mutex protects the access to this structure (or most of its
131 	 * fields).
132 	 */
133 	kmutex_t		port_mutex;
134 	/*
135 	 * This is the link to the next fcp_port structure in the global
136 	 * list.  The head of the global list is fcp_port_head and is
137 	 * defined in fcp.c.  This field is NULL for the last element of
138 	 * the global list.
139 	 */
140 	struct fcp_port		*port_next;
141 	/*
142 	 * This field points to the head of a list of internal requests that
143 	 * will be retried later.  Examples of internal requests are:
144 	 * 'Send a PRLI ELS', 'Send a PRLO ELS', 'Send a PLOGI ELS' or
145 	 * 'Send an Inquiry command'.  If the submission of the request to the
146 	 * fp/fctl module failed (for a set of specific reasons) and the
147 	 * request can be resubmitted later, it is queued here.	 The watchdog
148 	 * timer (fcp_watch()) will walk this queue and resubmit the requests.
149 	 */
150 	struct fcp_ipkt		*port_ipkt_list;
151 	/*
152 	 * This seems to be used as a temporary device counter during a
153 	 * discovery process (or reconfiguration as some comments put it).
154 	 * It seems to be initialized in fcp_statec_callback() with the
155 	 * number of devices that fp/fctl saw after the line came up and
156 	 * is supposed to reached zero when the reconfiguration process is
157 	 * over.
158 	 */
159 	int			port_tmp_cnt;
160 	/*
161 	 * This is supposed to indicate the state of this port.	 It is a
162 	 * bitmap which means several bits can be set simultaneously.  The list
163 	 * of the different bits and their meaning is given further down in
164 	 * this file.
165 	 */
166 	uint32_t		port_state;
167 	/*
168 	 * This field is initialized at the very end of the function
169 	 * fcp_handle_port_attach() if the attachment of the port was
170 	 * successful.	It is set to the value stored in lbolt64 at the
171 	 * time of the attachment.  This value is only used in the function
172 	 * fcp_scsi_bus_config().  It is used to determine the value of the
173 	 * parameter timeout when ndi_busop_bus_config() and cv_wait() are
174 	 * called.  It actually serves to figure out how long the enumeration
175 	 * can be delayed (the max value being FCP_INIT_WAIT_TIMEOUT).
176 	 */
177 	int64_t			port_attach_time;
178 	/*
179 	 * This field contains the topology of the SAN the port is connected
180 	 * to.
181 	 */
182 	uint32_t		port_topology;
183 	/*
184 	 * This field contains the local port ID.  It is provided by fp/fctl
185 	 * when calling fcp_statec_callback() and fcp_port_attach().  This
186 	 * value is used to build Fibre Channel headers (like for PLOGI or
187 	 * PRLI).
188 	 */
189 	uint32_t		port_id;
190 	/*
191 	 * This field keeps track of the physical port state (fcp_port being
192 	 * more like the FCP software port state).  The information stored here
193 	 * is provided by fp/fctl except in two instances: in
194 	 * fcp_handle_port_attach() and fcp_handle_port_resume(). The values
195 	 * this field can take are defined in fctl.h.
196 	 */
197 	uint32_t		port_phys_state;
198 	/*
199 	 * This field points to the first element of a list of fcp_reset_elem
200 	 * structures.	Those structures are created when the target driver
201 	 * calls fcp_reset_target().  The target or the LUN specified by the
202 	 * target driver is reset by sending a Task Management command.	 After
203 	 * the response has been received, a fcp_reset_elem structure is
204 	 * queued here and will remain queued for FCP_RESET_DELAY.  While
205 	 * the fcp_reset_elem structure is in this queue the LUNs of
206 	 * the target to reset or the LUN to reset is set to LUN_BUSY state.
207 	 * In fcp_watch() the timeout is tested.  If the timout has expired,
208 	 * the fcp_reset_elem structure is unqueued and freed, and all the
209 	 * active commands for the target or LUNs are aborted.
210 	 */
211 	struct fcp_reset_elem	*port_reset_list;
212 	/*
213 	 * This points to the first element of a list of fcp_tgt_elem
214 	 * structures.	This list is a list of targets to offline.  The list
215 	 * is walked in fcp_watch(). After the target is offlined the
216 	 * structure fcp_tgt_elem is freed.
217 	 */
218 	struct fcp_tgt_elem	*port_offline_tgts;
219 	/*
220 	 * This points to the first element of a list of fcp_lun_elem
221 	 * structures.	This list is a list of LUNs to offline.	 The list
222 	 * is walked in fcp_watch(). After the lun is offlined the
223 	 * structure fcp_lun_elem is freed.
224 	 */
225 	struct fcp_lun_elem	*port_offline_luns;
226 	/*
227 	 * This field is a counter initialized to 1 when the port attaches.
228 	 * It is incremented when the line goes from online to offline and
229 	 * vice versa.	It is also incremented when the port detaches.	The
230 	 * value stored in this counter is used as a reference in time of the
231 	 * link state.	For example, when the line comes up internal requests
232 	 * are generated (fcp_ipkt) such as PRLI and INQUIRY.  Those requests
233 	 * are tagged with the value contained in this field at the time the
234 	 * request is built.  When the callback for the request is called, the
235 	 * current value of port_link_cnt is checked against the one set in
236 	 * the internal request structure.  If they don't match, it means the
237 	 * the request is not relevant anymore to the current line state and
238 	 * must be discarded (in between a request is issued and the callback
239 	 * routine is called the line may have bounced).  This is the way FCP
240 	 * identifies the requests that were hanging out when the state of the
241 	 * line changed.
242 	 */
243 	uint32_t		port_link_cnt;
244 	/*
245 	 * This field, as its name suggests, specifies a deadline for the
246 	 * overall discovery process.  It is initialized in three cases:
247 	 *
248 	 * 1) When the line goes from the offline state to the online state.
249 	 * 2) When the FP/FCTL called fcp_statec_callback() indicating that
250 	 *    a notification was received from the fabric indicating that a new
251 	 *    port showed up or that one disappeared.
252 	 * 3) In the fcp_create_on_demand() function (called because of an
253 	 *    ioctl).
254 	 *
255 	 * In all instances it is set to:
256 	 *
257 	 *	fcp_watchdog_time + FCP_ICMD_DEADLINE
258 	 *
259 	 * In all those instances a discovery process is started or extended
260 	 * (2).	 The value stored in port_deadline is only checked in one
261 	 * function: fcp_is_retryable().  That function checks if an
262 	 * internal command (fcp_ipkt) is retryable or not.  Usually
263 	 * there's a counter that limits the number of times a command is
264 	 * retried (Max value is FCP_MAX_RETRIES).  However, even if the
265 	 * counter hasn't exceeded that value, the command will not be retried
266 	 * past the deadline.  This means that the discovery process has to
267 	 * be finished before port_deadline.  In other words, an internal
268 	 * command retry capability is limited numerically and in time.
269 	 */
270 	int			port_deadline;
271 	/*
272 	 * This is the Node WWN of the local port.  It is initialized
273 	 * during the port attachment.
274 	 */
275 	la_wwn_t		port_nwwn;
276 	/*
277 	 * This is the Port WWN of the local port.  It is initialized during
278 	 * the port attachment.
279 	 */
280 	la_wwn_t		port_pwwn;
281 	/*
282 	 * This is the fp/fctl port handle.
283 	 */
284 	opaque_t		*port_fp_handle;
285 	/*
286 	 * The following 4 fields handle the queue of fcp_pkt outstanding for
287 	 * this port.
288 	 *
289 	 *   port_pkt_mutex	Protects the access to the queue
290 	 *   port_pkt_head	Points to the head of the queue
291 	 *   port_pkt_tail	Points to the tail of the queue
292 	 *   port_npkts	Number of commands outstanding (used only when
293 	 *			DEBUG is defined).
294 	 */
295 	kmutex_t		port_pkt_mutex;
296 	uint32_t		port_npkts;
297 	struct fcp_pkt		*port_pkt_head;
298 	struct fcp_pkt		*port_pkt_tail;
299 	/*
300 	 * This field is the counter of allocated and currently active
301 	 * fcp_ipkt.
302 	 */
303 	int			port_ipkt_cnt;
304 	/*
305 	 * Port instance provided by FP/FCTL.  It is actually deduced using
306 	 * ddi_get_instance() in fcp_port_attach().
307 	 */
308 	uint32_t		port_instance;
309 	/*
310 	 * Maximum number of exchanges the underlying physical FibreChannel
311 	 * port can handle.  This field is initialized during the port
312 	 * attachment but is never used.
313 	 */
314 	uint32_t		port_max_exch;
315 	/*
316 	 * This port stores the behavior expected of the underlying FCA driver
317 	 * when a port reset occurs.  The values stored here are defined in the
318 	 * file fc_types.h.
319 	 */
320 	fc_reset_action_t	port_reset_action;
321 	/*
322 	 * This port stores the DMA behavior of the underlying FCA driver.  It
323 	 * is checked only once in fcp_prepare_pkt() and, as the comment
324 	 * suggests, to work around an issue with an Intel PCI bridge.
325 	 */
326 	fc_dma_behavior_t	port_cmds_dma_flags;
327 	/*
328 	 * The value stored here indicates if the underlying FCA driver
329 	 * supports DMA transfers with non SCSI data (Ex: PRLI request).
330 	 */
331 	fc_fcp_dma_t		port_fcp_dma;
332 	/*
333 	 * This field contains the size of the private space required by the
334 	 * underlying FCA driver in a FibreChannel packet (fc_packet_t).
335 	 */
336 	uint32_t		port_priv_pkt_len;
337 	/*
338 	 * This field contains the port's modlink info.	 It is provided by
339 	 * FP/FCTL during the port attachment.
340 	 */
341 	struct modlinkage	port_fp_modlinkage;
342 	/*
343 	 * DMA attributes for data packets, commands and responses.
344 	 */
345 	ddi_dma_attr_t		port_data_dma_attr;
346 	ddi_dma_attr_t		port_cmd_dma_attr;
347 	ddi_dma_attr_t		port_resp_dma_attr;
348 	ddi_device_acc_attr_t	port_dma_acc_attr;
349 	/*
350 	 * Field containing the hba_tran structure registered with SCSA.
351 	 */
352 	struct scsi_hba_tran	*port_tran;
353 	/*
354 	 * Device info structure provided by fp/fctl when the port attaches and
355 	 * representing the local physical fibre channel port.
356 	 */
357 	dev_info_t		*port_dip;
358 	/*
359 	 * Head of the list of callback routines to call when a bus reset
360 	 * occurs.  This list is  populated by the targets drivers by calling
361 	 * fcp_scsi_reset_notify() (tran_reset_notify(9E)).
362 	 */
363 	struct scsi_reset_notify_entry	*port_reset_notify_listf;
364 	/*
365 	 * for framework event management
366 	 */
367 	ndi_event_definition_t	*port_ndi_event_defs;
368 	ndi_event_hdl_t		port_ndi_event_hdl;
369 	ndi_event_set_t		port_ndi_events;
370 	/*
371 	 * hash lists of targets attached to this port.	  The hashing is based
372 	 * on the WWN.
373 	 */
374 	struct fcp_tgt		*port_tgt_hash_table[FCP_NUM_HASH];
375 	/*
376 	 * per-Port control flag.  By default mpxio is enabled on ports unless
377 	 * explicitly disabled through driver.conf.
378 	 */
379 	int			port_mpxio;
380 	/*
381 	 * Value used as a flag to determine if the throttling has been
382 	 * set/initialized in the FCA driver.
383 	 */
384 	int			port_notify;
385 	/*
386 	 * This field contains a string initialized at attachment time and used
387 	 * when calling the function the function fc_trace_debug() (through
388 	 * the macro FCP_TRACE and FCP_DTRACE) to identify the port that
389 	 * logged the message.
390 	 */
391 	char			port_instbuf[24];
392 	uchar_t			port_boot_wwn[FC_WWN_SIZE];
393 
394 #ifdef	DEBUG
395 	/*
396 	 * Use once in fcp_finish_init() when calling getpcstack().
397 	 */
398 	int			port_finish_depth;
399 	pc_t			port_finish_stack[FCP_STACK_DEPTH];
400 #endif /* DEBUG */
401 	/*
402 	 * Condition variable used during the bus enumeration process.
403 	 */
404 	kcondvar_t		port_config_cv;
405 	/*
406 	 * Size (in bytes) required to hold the cookies of a scatter/gather
407 	 * list.
408 	 */
409 	int			port_dmacookie_sz;
410 } fcp_port_t;
411 
412 /*
413  * We need to save the target change count values in a map tag so as
414  * to uniquely identify the cause and handle it better as they change
415  * counts are bound to change upon receiving more state changes.
416  */
417 typedef int fcp_map_tag_t;
418 
419 /*
420  * fcp_state definitions.
421  */
422 #define	FCP_STATE_INIT			0x0001
423 #define	FCP_STATE_OFFLINE		0x0002
424 #define	FCP_STATE_ONLINE		0x0004
425 #define	FCP_STATE_SUSPENDED		0x0008
426 #define	FCP_STATE_POWER_DOWN		0x0010
427 #define	FCP_STATE_ONLINING		0x0020
428 #define	FCP_STATE_DETACHING		0x0040
429 #define	FCP_STATE_IN_WATCHDOG		0x0080
430 #define	FCP_STATE_IN_MDI		0x0100	/* Not in S8/S9 */
431 #define	FCP_STATE_NS_REG_FAILED		0x0200	/* Diff value from S8/S9 */
432 /*
433  * FCP_STATE_IN_CB_DEVC indicates that we're handling a state change
434  * notification that will be changing the state of devices.  This is an
435  * indication to fcp_scsi_start that the target's status might change.
436  */
437 #define	FCP_STATE_IN_CB_DEVC		0x0400
438 
439 /*
440  * FCP_STATE_FCA_IS_NODMA indicates that FCA doesn't support DMA at all
441  */
442 #define	FCP_STATE_FCA_IS_NODMA		0x80000000
443 
444 #define	FCP_MAX_DEVICES			127
445 
446 /* To remember that dip was allocated for a lun on this target. */
447 
448 #define	FCP_DEVICE_CREATED		0x1
449 
450 #define	FCP_EVENT_TAG_INSERT		0
451 #define	FCP_EVENT_TAG_REMOVE		1
452 
453 /*
454  * fcp_pkt: FCP packet
455  * ---------------------
456  *
457  * This structure is the one initialized/created in the tran_init_pkt(9E).  It
458  * embeds the fc_packet structure eventually passed to fp/fctl as well as
459  * the scsi_pkt returned by tran_init_pkt(9E) to the target driver.  There is
460  * a 1-to-1 correlation between the scsi_pkt, the fcp_pkt and the
461  * fc_packet.
462  *
463  * This is what a fcp_pkt looks like after allocation:
464  *
465  *			+================================+
466  *		 +--->	|	 struct scsi_pkt	 |
467  *		 |	|				 |
468  *		 | +--- | pkt_ha_private		 |
469  *		 | |	|				 |
470  *		 | |	+================================+
471  *		 | |
472  *		 | |	+================================+
473  *		 | +--> |	 struct fcp_pkt		 | <---------+
474  *		 +----- | cmd_pkt			 |	     |
475  *			|		      cmd_fp_pkt | ---+	     |
476  *	     +--------->| cmd_fcp_rsp[]			 |    |	     |
477  *	     | +------->| cmd_fcp_cmd[]			 |    |	     |
478  *	     | |	|--------------------------------|    |	     |
479  *	     | |	|	 struct fc_packet	 | <--+	     |
480  *	     | |	|				 |	     |
481  *	     | |	|		 pkt_ulp_private | ----------+
482  *	     | |	|		 pkt_fca_private | -----+
483  *	     | |	|		 pkt_data_cookie | ---+ |
484  *	     | |	| pkt_cmdlen			 |    | |
485  *	     | |(a)	| pkt_rsplen			 |    | |
486  *	     | +--------| .......... pkt_cmd ........... | ---|-|-------+
487  *	     |	(a)	|		  pkt_cmd_cookie | ---|-|-----+ |
488  *	     +----------| .......... pkt_resp .......... | ---|-|---+ | |
489  *			|		 pkt_resp_cookie | ---|-|-+ | | |
490  *			| pkt_cmd_dma			 |    | | | | | |
491  *			| pkt_cmd_acc			 |    | | | | | |
492  *			+================================+    | | | | | |
493  *			|	  dma_cookies		 | <--+ | | | | |
494  *			|				 |	| | | | |
495  *			+================================+	| | | | |
496  *			|	  fca_private		 | <----+ | | | |
497  *			|				 |	  | | | |
498  *			+================================+	  | | | |
499  *								  | | | |
500  *								  | | | |
501  *			+================================+   (b)  | | | |
502  *			|	 fcp_resp cookies	 | <------+ | | |
503  *			|				 |	    | | |
504  *			+================================+	    | | |
505  *								    | | |
506  *			+================================+   (b)    | | |
507  *			|	     fcp_resp		 | <--------+ | |
508  *			|   (DMA resources associated)	 |	      | |
509  *			+================================+	      | |
510  *								      | |
511  *								      | |
512  *								      | |
513  *			+================================+   (b)      | |
514  *			|	  fcp_cmd cookies	 | <----------+ |
515  *			|				 |		|
516  *			+================================+		|
517  *									|
518  *			+================================+   (b)	|
519  *			|	     fcp_cmd		 | <------------+
520  *			|   (DMA resources associated)	 |
521  *			+================================+
522  *
523  *
524  * (a)	The underlying FCA does NOT support DMA for this field
525  * (b)	The underlying FCA supports DMA for this field
526  */
527 typedef struct fcp_pkt {
528 	/*
529 	 * The two following fields are used to queue fcp_pkt in the double
530 	 * link list of the lun structure.  The packet is queued in
531 	 * tran_init_pkt(9E) and unqueued in tran_destroy_pkt(9E).
532 	 */
533 	struct fcp_pkt		*cmd_forw;
534 	struct fcp_pkt		*cmd_back;
535 	/*
536 	 * This field is used to queue the packet in the single link list of the
537 	 * port structure.  The port keeps a list of all the commands issued
538 	 * through it and scans it, for example, when all of those commands
539 	 * have to be aborted.
540 	 */
541 	struct fcp_pkt		*cmd_next;
542 	/*
543 	 * This field points back to the scsi_pkt.
544 	 */
545 	struct scsi_pkt		*cmd_pkt;
546 	/*
547 	 * This field points to the field cmd_fc_packet defined further in this
548 	 * same structure.
549 	 */
550 	struct fc_packet	*cmd_fp_pkt;
551 	/*
552 	 * Structure where the FCP_CMD information unit is going to be built.
553 	 */
554 	fcp_cmd_t		cmd_fcp_cmd;
555 	/*
556 	 * State of the packet.	 The values for the state seem to indicate
557 	 * that it isn't a bitmap.  However, in several instances the code
558 	 * treats it as a bitmap doing a "&= ~FCP_PKT_ISSUED" to it
559 	 * eventhough the value stored is always checked using "!=" and "==".
560 	 */
561 	uint_t			cmd_state;
562 	/*
563 	 * This field is a bitmap indicating if
564 	 * the cmd is queued
565 	 */
566 	uint_t			cmd_flags;
567 	/* Contains the number of bytes DMA mappped. */
568 	uint_t			cmd_dmacount;
569 	/*
570 	 * Contains the timeout value for the packet.  This is not a delay or
571 	 * a delta but an absolute value.
572 	 */
573 	uint_t			cmd_timeout;
574 	/*
575 	 * This array is used to store the FCP_RSP information unit returned by
576 	 * the device when the underlying FCA cannot DMA it in.
577 	 */
578 	char			cmd_fcp_rsp[FCP_MAX_RSP_IU_SIZE];
579 	/*
580 	 * This is the fc_packet structure used to forward the request to
581 	 * fp/fctl.
582 	 */
583 	struct fc_packet	cmd_fc_packet;
584 } fcp_pkt_t;
585 
586 /*
587  * fcp_ipkt : Packet for internal commands.
588  * ------------------------------------------
589  *
590  *			+================================+
591  *			|	 struct fcp_ipkt	 | <---------+
592  *			|	 (kmem_zalloc())	 |	     |
593  *			|		       ipkt_fpkt | ---+	     |
594  *			|				 |    |	     |
595  *			|     ipkt_cmdlen = cmd_len	 |    |	     |
596  *			|				 |    |	     |
597  *			|				 |    |	     |
598  *			|				 |    |	     |
599  *			|--------------------------------|    |	     |
600  *			|	 struct fc_packet	 | <--+	     |
601  *			|				 |	     |
602  *			|		 pkt_ulp_private | ----------+
603  *			|		 pkt_fca_private | -----+
604  *			|		 pkt_data_cookie | ---+ |
605  *			|	    pkt_cmdlen		 |    | |
606  *			|	    pkt_rsplen		 |    | |
607  *			| pkt_cmd ...................... | ---|-|-------+
608  *			|		  pkt_cmd_cookie | ---|-|-----+ |
609  *			| pkt_resp ..................... | ---|-|---+ | |
610  *			|		 pkt_resp_cookie | ---|-|-+ | | |
611  *			|	   pkt_cmd_dma		 |    | | | | | |
612  *			|	   pkt_cmd_acc		 |    | | | | | |
613  *			+================================+    | | | | | |
614  *			|	  dma_cookies		 | <--+ | | | | |
615  *			|				 |	| | | | |
616  *			|				 |	| | | | |
617  *			|				 |	| | | | |
618  *			+================================+	| | | | |
619  *			|	  fca_private		 | <----+ | | | |
620  *			|				 |	  | | | |
621  *			|				 |	  | | | |
622  *			|				 |	  | | | |
623  *			+================================+	  | | | |
624  *								  | | | |
625  *								  | | | |
626  *			+================================+   (b)  | | | |
627  *			|	 fcp_resp cookies	 | <------+ | | |
628  *			|				 |	    | | |
629  *			+================================+	    | | |
630  *								    | | |
631  *			+================================+   (b)    | | |
632  *			|	     fcp_resp		 | <--------+ | |
633  *			|   (DMA resources associated)	 |	      | |
634  *			+================================+	      | |
635  *								      | |
636  *								      | |
637  *								      | |
638  *			+================================+   (b)      | |
639  *			|	  fcp_cmd cookies	 | <----------+ |
640  *			|				 |		|
641  *			+================================+		|
642  *									|
643  *			+================================+   (b)	|
644  *			|	     fcp_cmd		 | <------------+
645  *			|   (DMA resources associated)	 |
646  *			+================================+
647  *
648  * (a)	The underlying FCA does NOT support DMA for this field
649  * (b)	The underlying FCA supports DMA for this field
650  */
651 typedef struct fcp_ipkt {
652 	/*
653 	 * Pointer to the port (fcp_port) in behalf of which this internal
654 	 * packet was allocated.
655 	 */
656 	struct fcp_port		*ipkt_port;
657 	/*
658 	 * Pointer to the target (fcp_tgt) in behalf of which this internal
659 	 * packet was allocated.
660 	 */
661 	struct fcp_tgt		*ipkt_tgt;
662 	/*
663 	 * Pointer to the lun (fcp_lun) in behalf of which this internal
664 	 * packet was allocated.  This field is only meaningful when the
665 	 * internal packet has been allocated for a "scsi passthru" command or
666 	 * for an internal SCSI command such as REPORT LUNs and INQUIRY.
667 	 */
668 	struct fcp_lun		*ipkt_lun;
669 	/*
670 	 * Fields used to queue the internal packet into the double linked list
671 	 * of the FCP port (fcp_port).
672 	 */
673 	struct fcp_ipkt		*ipkt_next;
674 	struct fcp_ipkt		*ipkt_prev;
675 	/*
676 	 * This field points to the field ipkt_fc_packet defined farther in
677 	 * this same structure.
678 	 */
679 	struct fc_packet	*ipkt_fpkt;
680 	/*
681 	 * This is the timeout value for the internal packet.  It seems to
682 	 * increase with the number of retries.	 It is initialized like this
683 	 * in the code:
684 	 *
685 	 *   icmd->ipkt_restart = fcp_watchdog_time + icmd->ipkt_retries++
686 	 *
687 	 * First time ipkt_retries is zero.  As it increases, the timeout
688 	 * value for the internal packet also increases.
689 	 */
690 	uint32_t		ipkt_restart;
691 	/*
692 	 * Link state counter when the internal packet was built.
693 	 */
694 	uint32_t		ipkt_link_cnt;
695 	int			ipkt_cause;
696 	uint32_t		ipkt_cmdlen;
697 	uint32_t		ipkt_resplen;
698 	uint32_t		ipkt_datalen;
699 	/*
700 	 * Counter of the times an internal packet has been retried.  Its
701 	 * value is checked against FCP_MAX_RETRIES.
702 	 */
703 	uint32_t		ipkt_retries;
704 	uint32_t		ipkt_change_cnt;
705 	int			ipkt_nodma;
706 	/*
707 	 * Semaphore used to wait for completion on.
708 	 */
709 	ksema_t			ipkt_sema;
710 	/*
711 	 * Opcode indicating what internal command the packet contains (PLOGI,
712 	 * PRLI, INQUIRY...).
713 	 */
714 	uchar_t			ipkt_opcode;
715 	/*
716 	 * FC packet.
717 	 */
718 	struct fc_packet	ipkt_fc_packet;
719 } fcp_ipkt_t;
720 
721 /*
722  * cmd_state definitions
723  */
724 #define	FCP_PKT_IDLE			0x1
725 #define	FCP_PKT_ISSUED			0x2
726 #define	FCP_PKT_ABORTING		0x3
727 
728 /*
729  * These are the defined cmd_flags for this structure.
730  */
731 #define	CFLAG_NONE		0x0000
732 #define	CFLAG_IS_READ		0x0001
733 #define	CFLAG_IN_QUEUE		0x0002	/* command in fcp queue */
734 
735 /*
736  * Target structure
737  * ----------------
738  *
739  * This structure holds the information relative to a SCSI target.  This
740  * structure doesn't represent the object registered with the OS (NDI or
741  * MPxIO...).
742  */
743 typedef struct fcp_tgt {
744 	/*
745 	 * This field is used to queue the target structure in one of the
746 	 * buckets of the fcp_port target hash table port_tgt_hash_table[].
747 	 */
748 	struct fcp_tgt		*tgt_next;
749 	/* Points to the fcp_port the target belongs to. */
750 	struct fcp_port		*tgt_port;
751 	/*
752 	 * This field is a bitmap indicating the state of the target.  Several
753 	 * bits can be set simultaneously.
754 	 */
755 	uint32_t		tgt_state;
756 	/*
757 	 * State controlling if the LUNs attached to this target will be
758 	 * automatically onlined or not.
759 	 */
760 	uint32_t		tgt_node_state;
761 	/*
762 	 * Mutex protecting this structure.
763 	 */
764 	kmutex_t		tgt_mutex;
765 	/*
766 	 * List of LUNs (single link list).
767 	 */
768 	struct fcp_lun		*tgt_lun;
769 	opaque_t		tgt_fca_dev;
770 	/*
771 	 * Number of LUNs in this target.
772 	 */
773 	uint_t			tgt_lun_cnt;
774 	/*
775 	 * Counter of LUNs to probe.  It is used during the discovery
776 	 * process.  Starts with the number of LUNs returned by REPORT_LUN
777 	 * and is decremented until it reaches zero.
778 	 */
779 	uint_t			tgt_tmp_cnt;
780 	/*
781 	 * fp/fctl handle for the "port_device".
782 	 */
783 	opaque_t		tgt_pd_handle;
784 	/*
785 	 * Node World Wide Name.
786 	 */
787 	la_wwn_t		tgt_node_wwn;
788 	/*
789 	 * Port World Wide Name.
790 	 */
791 	la_wwn_t		tgt_port_wwn;
792 	/*
793 	 * Fibre Channel Port ID.
794 	 */
795 	uint32_t		tgt_d_id;
796 	/*
797 	 * Fibre Channel Port ID.  Uses bit fields to represent it.
798 	 */
799 	uint32_t		tgt_hard_addr;
800 	/*
801 	 * Becomes 1 when the LUNs are created.
802 	 */
803 	uchar_t			tgt_device_created;
804 	/*
805 	 * Counter of how many REPORT_LUN commands were sent.  It is used to
806 	 * allow the REPORT_LUN command to be sent twice in case the buffer
807 	 * allocated the first time wasn't big enough.
808 	 */
809 	uchar_t			tgt_report_lun_cnt;
810 	/*
811 	 * This field is incremented each time the field tgt_state is updated.
812 	 * Its use is similar to the use of the field port_link_cnt in the
813 	 * fcp_port structure.	The internal packets are, for example, tagged
814 	 * with the value stored here.
815 	 */
816 	uint32_t		tgt_change_cnt;
817 	/*
818 	 * This field contains the cause of the last change in state.
819 	 */
820 	int			tgt_statec_cause;
821 	/*
822 	 * The following two fields indicate whether the remote port is an
823 	 * FCP initiator or an FCP target.  They are treated as booleans.
824 	 */
825 	uchar_t			tgt_icap;	/* Initiator */
826 	uchar_t			tgt_tcap;	/* Target */
827 #ifdef	DEBUG
828 	/*
829 	 * Updated in fcp_call_finish_init_held() when DEBUG  is defined
830 	 */
831 	int			tgt_tmp_cnt_depth;
832 	pc_t			tgt_tmp_cnt_stack[FCP_STACK_DEPTH];
833 #endif /* DEBUG */
834 	/*
835 	 * This field holds the timer id of the timer started when a LUN
836 	 * reconfiguration is needed for the target.  The reconfiguration
837 	 * is done in the timeout function.
838 	 */
839 	timeout_id_t		tgt_tid;
840 	int			tgt_done;
841 	/*
842 	 * Bitmap used to trace the discovery process.
843 	 */
844 	uint32_t		tgt_trace;
845 	/*
846 	 * This field is used when the code is sorting out which devices
847 	 * were known which ones are new and which ones went away.
848 	 */
849 	uint32_t		tgt_aux_state;
850 	/*
851 	 * Number of internal packets allocated in behalf of the target.
852 	 */
853 	int			tgt_ipkt_cnt;
854 	/*
855 	 * used to detect user unconfig when auto configuration is enabled.
856 	 */
857 	uint32_t		tgt_manual_config_only;
858 } fcp_tgt_t;
859 
860 /*
861  * Target States
862  */
863 #define	FCP_TGT_INIT		0x01
864 #define	FCP_TGT_BUSY		0x02
865 #define	FCP_TGT_MARK		0x04
866 #define	FCP_TGT_OFFLINE		0x08
867 #define	FCP_TGT_ORPHAN		0x80
868 #define	FCP_TGT_ILLREQ		0x10
869 
870 /*
871  * Target Aux Stat
872  */
873 #define	FCP_TGT_TAGGED		0x01
874 
875 /*
876  * Target discovery tracing
877  */
878 #define	FCP_TGT_TRACE_1		0x00000001
879 #define	FCP_TGT_TRACE_2		0x00000002
880 #define	FCP_TGT_TRACE_3		0x00000004
881 #define	FCP_TGT_TRACE_4		0x00000008
882 #define	FCP_TGT_TRACE_5		0x00000010
883 #define	FCP_TGT_TRACE_6		0x00000020
884 #define	FCP_TGT_TRACE_7		0x00000040
885 #define	FCP_TGT_TRACE_8		0x00000080
886 #define	FCP_TGT_TRACE_9		0x00000100
887 #define	FCP_TGT_TRACE_10	0x00000200
888 #define	FCP_TGT_TRACE_11	0x00000400
889 #define	FCP_TGT_TRACE_12	0x00000800
890 #define	FCP_TGT_TRACE_13	0x00001000
891 #define	FCP_TGT_TRACE_14	0x00002000
892 #define	FCP_TGT_TRACE_15	0x00004000
893 #define	FCP_TGT_TRACE_16	0x00008000
894 #define	FCP_TGT_TRACE_17	0x00010000
895 #define	FCP_TGT_TRACE_18	0x00020000
896 #define	FCP_TGT_TRACE_19	0x00040000
897 #define	FCP_TGT_TRACE_20	0x00080000
898 #define	FCP_TGT_TRACE_21	0x00100000
899 #define	FCP_TGT_TRACE_22	0x00200000
900 #define	FCP_TGT_TRACE_23	0x00400000
901 #define	FCP_TGT_TRACE_24	0x00800000
902 #define	FCP_TGT_TRACE_25	0x01000000
903 #define	FCP_TGT_TRACE_26	0x02000000
904 #define	FCP_TGT_TRACE_27	0x04000000
905 #define	FCP_TGT_TRACE_28	0x08000000
906 #define	FCP_TGT_TRACE_29	0x10000000
907 
908 #ifndef	__lock_lint
909 
910 #define	FCP_TGT_TRACE(ptgt, tcount, bit) {\
911 	if (ptgt) {\
912 		if (ptgt->tgt_change_cnt == tcount) {\
913 			ptgt->tgt_trace |= bit;\
914 		}\
915 	}\
916 }
917 
918 #else	/* __lock_lint */
919 
920 #define	FCP_TGT_TRACE(ptgt, tcount, bit)
921 
922 #endif /* __lock_lint */
923 
924 
925 /*
926  * state change cause
927  */
928 #define	FCP_CAUSE_TGT_CHANGE	0x01
929 #define	FCP_CAUSE_LINK_CHANGE	0x02
930 #define	FCP_CAUSE_LINK_DOWN	0x04
931 #define	FCP_CAUSE_USER_CREATE	0x08
932 
933 
934 /*
935  * Target node states (applicable to LUNs behind the target)
936  */
937 #define	FCP_TGT_NODE_NONE	0x00	/* No node exists */
938 #define	FCP_TGT_NODE_ON_DEMAND	0x01	/* create only upon request */
939 #define	FCP_TGT_NODE_PRESENT	0x02	/* Node exists; rediscover it */
940 
941 
942 #define	FCP_NO_CHANGE		0x1
943 #define	FCP_LINK_CHANGE		0x2
944 #define	FCP_DEV_CHANGE		0x3
945 
946 
947 /* hotplug event struct */
948 struct fcp_hp_event {
949 	int (*callback)();
950 	void *arg;
951 };
952 
953 /*
954  * We talk to both NDI and MDI framework to enumerate our child devices.
955  * We internally define a generic child handle and assign either dev_info
956  * or mdi_pathinfo handle depending on the device.
957  */
958 typedef void		*child_info_t;
959 
960 #define	CIP(child)	((child_info_t *)(child))
961 #define	DIP(child)	((dev_info_t *)(child))
962 #define	PIP(child)	((mdi_pathinfo_t *)(child))
963 
964 /*
965  * LUN structure
966  * -------------
967  *
968  * This structure holds the information relative to a SCSI LUN.	 This
969  * structure is the one representing the object registered with the OS (NDI
970  * or MPxIO...).
971  */
972 typedef struct fcp_lun {
973 	/*
974 	 * Mutex protecting the access to this structure.
975 	 */
976 	kmutex_t		lun_mutex;
977 	/*
978 	 * Logical unit number.	 It is a SCSI3 format.
979 	 */
980 	fcp_ent_addr_t		lun_addr;
981 	/*
982 	 * The two following fields are respectively the head and tail of a
983 	 * double link list of fcp_packets.  It is populated in
984 	 * tran_init_pkt(9E) (fcp_scsi_init_pkt) and emptied in
985 	 * tran_destroy_pkt(9E) (fcp_scsi_destroy_pkt).
986 	 */
987 	struct fcp_pkt		*lun_pkt_head;
988 	struct fcp_pkt		*lun_pkt_tail;
989 	/*
990 	 * This field is treated like a union.	It may contain the dev_info_t
991 	 * or the mdi_pathinfo_t depending on how the device associated with
992 	 * this LUN was registered.
993 	 */
994 	child_info_t		*lun_cip;
995 	/*
996 	 * Online/Offline event count.
997 	 */
998 	int			lun_event_count;
999 	/*
1000 	 * Back pointer to the target the LUN belongs to.
1001 	 */
1002 	struct fcp_tgt		*lun_tgt;
1003 	/*
1004 	 * Bit map reflecting the state of the LUN.
1005 	 */
1006 	uint_t			lun_state;
1007 	/*
1008 	 * LUN type (disk, tape...).  The value stored here is taken from the
1009 	 * inquiry data.
1010 	 */
1011 	uchar_t			lun_type;
1012 	/*
1013 	 * This field is incremented each time fcp_scsi_tgt_init()
1014 	 * (tran_tgt_init(9E)) is called and decremented each time
1015 	 * fcp_scsi_tgt_free() (tran_tgt_free(9E)) is called.  The
1016 	 * incrementation and decrementation will also have an effect on
1017 	 * lun_state bit FCP_SCSI_LUN_TGT_INIT.
1018 	 */
1019 	uchar_t			lun_tgt_count;
1020 	/*
1021 	 * LUN number as it is returned by REPORT_LUNS.
1022 	 */
1023 	uint16_t		lun_num;
1024 	/*
1025 	 * Pointer to the next LUN.
1026 	 */
1027 	struct fcp_lun		*lun_next;
1028 	/*
1029 	 * lun level association with scsi_device
1030 	 */
1031 	struct scsi_device	*lun_sd;
1032 	/*
1033 	 * per-Lun control flag.  A value of '1' means the LUN is managed by
1034 	 * mpxio.  A value of '0' means the LUN has been physically enumerated
1035 	 * as a child of corresponding port driver node.
1036 	 */
1037 	int			lun_mpxio;
1038 	/*
1039 	 * Length of the GUID.
1040 	 */
1041 	size_t			lun_guid_size;
1042 	/*
1043 	 * Pointer to a buffer that contains the GUID.
1044 	 */
1045 	char			*lun_guid;
1046 	/*
1047 	 * Pointer to a buffer that contains the old GUID.
1048 	 */
1049 	char			*lun_old_guid;
1050 	/*
1051 	 * Length of the old GUID
1052 	 */
1053 	size_t			lun_old_guid_size;
1054 	/*
1055 	 * Bitmap used to track the LUN discovery process.
1056 	 */
1057 	uint32_t		lun_trace;
1058 	/*
1059 	 * Bitmap representing the SCSI capabilities.
1060 	 */
1061 	uchar_t			lun_cap;
1062 	/*
1063 	 * LUN inquiry data (as returned by the INQUIRY command).
1064 	 */
1065 	struct scsi_inquiry	lun_inq;
1066 } fcp_lun_t;
1067 
1068 
1069 /*
1070  * Lun discovery tracing
1071  */
1072 #define	FCP_LUN_TRACE_1		0x0000001
1073 #define	FCP_LUN_TRACE_2		0x0000002
1074 #define	FCP_LUN_TRACE_3		0x0000004
1075 #define	FCP_LUN_TRACE_4		0x0000008
1076 #define	FCP_LUN_TRACE_5		0x0000010
1077 #define	FCP_LUN_TRACE_6		0x0000020
1078 #define	FCP_LUN_TRACE_7		0x0000040
1079 #define	FCP_LUN_TRACE_8		0x0000080
1080 #define	FCP_LUN_TRACE_9		0x0000100
1081 #define	FCP_LUN_TRACE_10	0x0000200
1082 #define	FCP_LUN_TRACE_11	0x0000400
1083 #define	FCP_LUN_TRACE_12	0x0000800
1084 #define	FCP_LUN_TRACE_13	0x0001000
1085 #define	FCP_LUN_TRACE_14	0x0002000
1086 #define	FCP_LUN_TRACE_15	0x0004000
1087 #define	FCP_LUN_TRACE_16	0x0008000
1088 #define	FCP_LUN_TRACE_17	0x0010000
1089 #define	FCP_LUN_TRACE_18	0x0020000
1090 #define	FCP_LUN_TRACE_19	0x0040000
1091 #define	FCP_LUN_TRACE_20	0x0080000
1092 #define	FCP_LUN_TRACE_21	0x0100000
1093 #define	FCP_LUN_TRACE_22	0x0200000
1094 #define	FCP_LUN_TRACE_23	0x0400000
1095 #define	FCP_LUN_TRACE_24	0x0800000
1096 #define	FCP_LUN_TRACE_25	0x1000000
1097 #define	FCP_LUN_TRACE_26	0x2000000
1098 #define	FCP_LUN_TRACE_27	0x4000000
1099 #define	FCP_LUN_TRACE_28	0x8000000
1100 
1101 
1102 #define	FCP_LUN_TRACE(plun, bit) {\
1103 	if (plun && plun->lun_tgt) {\
1104 		mutex_enter(&plun->lun_tgt->tgt_mutex);\
1105 		plun->lun_trace |= bit;\
1106 		mutex_exit(&plun->lun_tgt->tgt_mutex);\
1107 	}\
1108 }
1109 
1110 #define	FCP_LUN_CAP_RESET	0x01
1111 
1112 /*
1113  * Lun State -- these have the same values as the target states so
1114  * that they can be interchanged (in cases where the same state occurs
1115  * for both targets and luns)
1116  */
1117 
1118 #define	FCP_LUN_INIT		FCP_TGT_INIT
1119 #define	FCP_LUN_BUSY		FCP_TGT_BUSY
1120 #define	FCP_LUN_MARK		FCP_TGT_MARK
1121 #define	FCP_LUN_OFFLINE		FCP_TGT_OFFLINE
1122 #define	FCP_SCSI_LUN_TGT_INIT	0x20	/* target/LUNs all inited */
1123 #define	FCP_LUN_DISAPPEARED	0x40
1124 /*
1125  * Use the below flag with caution as it is can cause a delay in
1126  * fcp_scsi_start() which is in the normal I/O performance path
1127  */
1128 #define	FCP_LUN_ONLINING	0x80
1129 /*
1130  * Set the below flag when the DTYPE or GUID of a LUN changes during discovery
1131  */
1132 #define	FCP_LUN_CHANGED	0x100
1133 /*
1134  * This flag is used specifically for the special lun: lun 0.
1135  */
1136 #define	FCP_LUN_DEVICE_NOT_CONNECTED	0x200
1137 
1138 /*
1139  * Report Lun Format
1140  */
1141 struct fcp_reportlun_resp {
1142 	uint32_t	num_lun;	/* num LUNs * 8 */
1143 	uint32_t	reserved;
1144 	longlong_t	lun_string[1];
1145 };
1146 
1147 /*
1148  * This structure actually represents a request executed by the hot plug task.
1149  */
1150 struct fcp_hp_elem {
1151 	/*
1152 	 * FCP port concerned by the request.
1153 	 */
1154 	struct fcp_port	*port;
1155 	/*
1156 	 * LUN concerned by the request.
1157 	 */
1158 	struct fcp_lun	*lun;
1159 	/*
1160 	 * dev_info_t or mdi_pathinfo_t pointer.
1161 	 */
1162 	child_info_t		*cip;
1163 	/*
1164 	 * lun_mpxio when the event is submitted
1165 	 */
1166 	int			old_lun_mpxio;
1167 	/*
1168 	 * What to do (offline, online...).
1169 	 */
1170 	int			what;
1171 	/*
1172 	 * FLags used when calling NDI fucntions.
1173 	 */
1174 	int			flags;
1175 	/*
1176 	 * Link state change count when the structure was created.
1177 	 */
1178 	int			link_cnt;
1179 	/*
1180 	 * Target state change count when the structure was created.
1181 	 */
1182 	int			tgt_cnt;
1183 	/*
1184 	 * Online/Offline count when this event was queued.
1185 	 */
1186 	int			event_cnt;
1187 	/*
1188 	 * This is the flag protected by the mutex and condition variable
1189 	 * defined further in this structure.  It is the flag indicating
1190 	 * that the hot plug task is done with the treatment of the structure.
1191 	 */
1192 	int			wait;
1193 	/*
1194 	 * This is where the result of the request is returned when the sender
1195 	 * waits for the completion.
1196 	 */
1197 	int			result;
1198 	/*
1199 	 * Condition variable used when wait is true.
1200 	 */
1201 	kcondvar_t		cv;
1202 	/*
1203 	 * Mutex used in conjunction with the previous condition variable.
1204 	 */
1205 	kmutex_t		mutex;
1206 };
1207 
1208 
1209 struct fcp_reset_elem {
1210 	struct fcp_reset_elem	*next;
1211 	struct fcp_tgt		*tgt;
1212 	struct fcp_lun		*lun;
1213 	clock_t			timeout;
1214 	uint_t			tgt_cnt;
1215 };
1216 
1217 /*
1218  * This structure is used to offline targets.  It is queued in the FCP port
1219  * structure single linked list port_offline_tgts and walked by the watchdog
1220  * timer.
1221  */
1222 struct fcp_tgt_elem {
1223 	/*
1224 	 * Points to the next element of the list.
1225 	 */
1226 	struct fcp_tgt_elem	*next;
1227 	/*
1228 	 * Points to the target to offline.
1229 	 */
1230 	struct fcp_tgt		*ptgt;
1231 	/*
1232 	 * Absolute time after which the target must be offlined.
1233 	 */
1234 	int			time;
1235 	/*
1236 	 * Link state change count when the structure was created.
1237 	 */
1238 	int			link_cnt;
1239 	/*
1240 	 * Target state change count when the structure was created.
1241 	 */
1242 	int			tgt_cnt;
1243 	/*
1244 	 * Flags providing information for the offline (when calling mdi or
1245 	 * ndi).
1246 	 */
1247 	int			flags;
1248 };
1249 
1250 /*
1251  * This structure is used to offline LUNs.  It is queued in the FCP port
1252  * structure single linked list port_offline_luns and walked by the watchdog
1253  * timer.
1254  */
1255 struct fcp_lun_elem {
1256 	/*
1257 	 * Points to the next element of the list.
1258 	 */
1259 	struct fcp_lun_elem	*next;
1260 	/*
1261 	 * Points to the LUN to offline.
1262 	 */
1263 	struct fcp_lun		*plun;
1264 	/*
1265 	 * Absolute time after which the LUN must be offlined.
1266 	 */
1267 	int			time;
1268 	/*
1269 	 * Link state change count when the structure was created.
1270 	 */
1271 	int			link_cnt;
1272 	/*
1273 	 * Target state change count when the structure was created.
1274 	 */
1275 	int			tgt_cnt;
1276 	/*
1277 	 * Flags providing information for the offline (when calling mdi or
1278 	 * ndi).
1279 	 */
1280 	int			flags;
1281 };
1282 
1283 /*
1284  * LUN masking
1285  */
1286 typedef struct fcp_black_list_entry {
1287 	/*
1288 	 * Points to the next element of the list.
1289 	 */
1290 	struct fcp_black_list_entry	*next;
1291 	/*
1292 	 * Port WWN of the target.
1293 	 */
1294 	la_wwn_t			wwn;
1295 	/*
1296 	 * LUN number which need to be masked.
1297 	 */
1298 	uint32_t			lun;
1299 	/*
1300 	 * Counter of access times.
1301 	 */
1302 	int				masked;
1303 } fcp_black_list_entry_t;
1304 
1305 #define	ADDR2FCP(ap)	((struct fcp_port *)		\
1306 		((ap)->a_hba_tran->tran_hba_private))
1307 #define	ADDR2LUN(ap)	((struct fcp_lun *)				\
1308 		scsi_device_hba_private_get(scsi_address_device(ap)))
1309 #define	CMD2PKT(cmd)	((cmd)->cmd_pkt)
1310 #define	PKT2CMD(pkt)	((struct fcp_pkt *)((pkt)->pkt_ha_private))
1311 
1312 /*
1313  * timeout values
1314  */
1315 #define	FCP_ELS_TIMEOUT		20	/* 20 seconds */
1316 #define	FCP_SCSI_CMD_TIMEOUT	25	/* 30 seconds */
1317 #define	FCP_POLL_TIMEOUT	60	/* 60 seconds */
1318 #define	FCP_TIMEOUT_DELTA	2	/* 2 seconds */
1319 #define	FCP_ICMD_DEADLINE	120	/* 60 seconds */
1320 #define	FCP_MAX_RETRIES		4
1321 
1322 
1323 #if !defined(__lint)
1324 _NOTE(MUTEX_PROTECTS_DATA(fcp_port::port_mutex,
1325     fcp_port::port_state fcp_tgt::tgt_change_cnt
1326     fcp_port::fcp_next fcp_port::port_tgt_hash_table
1327     fcp_port::port_link_cnt fcp_port::port_reset_list
1328     fcp_port::port_tmp_cnt fcp_port::port_ipkt_list
1329     fcp_tgt::tgt_next))
1330 
1331 _NOTE(MUTEX_PROTECTS_DATA(fcp_port::port_pkt_mutex,
1332     fcp_port::port_pkt_head fcp_port::port_pkt_tail
1333     fcp_port::port_npkts))
1334 
1335 _NOTE(MUTEX_PROTECTS_DATA(fcp_tgt::tgt_mutex,
1336     fcp_tgt::tgt_state	fcp_tgt::tgt_device_created
1337     fcp_tgt::tgt_icap fcp_tgt::tgt_tcap
1338     fcp_tgt::tgt_tid fcp_tgt::tgt_pd_handle fcp_tgt::tgt_tmp_cnt
1339     fcp_tgt::tgt_statec_cause fcp_lun::lun_next fcp_lun::lun_state))
1340 
1341 _NOTE(LOCK_ORDER(fcp_port::fcp_mutex fcp_tgt::tgt_mutex))
1342 _NOTE(LOCK_ORDER(fcp_tgt::tgt_mutex fcp_lun::lun_mutex))
1343 
1344 _NOTE(MUTEX_PROTECTS_DATA(fcp_lun::lun_mutex,
1345     fcp_lun::lun_pkt_head fcp_lun::lun_pkt_tail
1346     fcp_lun::lun_cip fcp_lun::lun_mpxio))
1347 
1348 _NOTE(DATA_READABLE_WITHOUT_LOCK( fcp_tgt::tgt_state))
1349 _NOTE(DATA_READABLE_WITHOUT_LOCK( fcp_tgt::tgt_pd_handle))
1350 
1351 _NOTE(DATA_READABLE_WITHOUT_LOCK(fcp_tgt::tgt_tid))
1352 
1353 
1354 _NOTE(SCHEME_PROTECTS_DATA("Safe Data",
1355     fcp_port::port_dma_acc_attr
1356     fcp_port::port_fcp_dma fcp_port::fcp_tran
1357     fcp_port::port_ndi_events fcp_port::port_ndi_event_defs
1358     fcp_port::port_pkt_cache fcp_port::port_dip fcp_port::port_phys_state
1359     fcp_port::port_reset_action fcp_port::port_cmds_dma_flags
1360     fcp_port::port_fp_handle fcp_port::port_instance
1361     fcp_port::port_fp_modlinkage fcp_port::port_max_exch
1362     fcp_port::port_priv_pkt_len fcp_port::port_id
1363     fcp_port::port_topology fcp_port::port_deadline fcp_port::port_mpxio
1364     fcp_tgt::tgt_d_id fcp_tgt::tgt_hard_addr fcp_tgt::tgt_lun_cnt
1365     fcp_tgt::tgt_port fcp_lun::lun_num fcp_lun::lun_tgt
1366     fcp_lun::lun_type
1367     fcp_lun::lun_guid_size fcp_lun::lun_guid
1368     fcp_hp_elem::lun fcp_hp_elem::flags fcp_hp_elem::cip
1369     fcp_hp_elem::what fcp_hp_elem::tgt_cnt fcp_hp_elem::tgt_cnt
1370     fcp_hp_elem::link_cnt fcp_reset_elem fcp_pkt fcp_ipkt
1371     scsi_pkt scsi_arq_status scsi_device scsi_hba_tran scsi_cdb))
1372 #endif	/* __lint */
1373 
1374 /*
1375  * Local variable "pptr" must exist before using these
1376  */
1377 #define	FCP_CP_IN(s, d, handle, len)					\
1378 	{								\
1379 		if (!((pptr)->port_state & FCP_STATE_FCA_IS_NODMA)) {	\
1380 			ddi_rep_get8((handle), (uint8_t *)(d),		\
1381 			    (uint8_t *)(s), (len), DDI_DEV_AUTOINCR);	\
1382 		} else {						\
1383 			bcopy((s), (d), (len));				\
1384 		}							\
1385 	}
1386 
1387 #define	FCP_CP_OUT(s, d, handle, len)				\
1388 	{								\
1389 		if (!((pptr)->port_state & FCP_STATE_FCA_IS_NODMA)) {	\
1390 			ddi_rep_put8((handle), (uint8_t *)(s),		\
1391 			    (uint8_t *)(d), (len), DDI_DEV_AUTOINCR);	\
1392 		} else {						\
1393 			bcopy((s), (d), (len));				\
1394 		}							\
1395 	}
1396 
1397 #define	FCP_ONLINE			0x1
1398 #define	FCP_OFFLINE			0x2
1399 #define	FCP_MPXIO_PATH_CLEAR_BUSY	0x3
1400 #define	FCP_MPXIO_PATH_SET_BUSY		0x4
1401 
1402 #define	FCP_IDLE			0x00
1403 #define	FCP_OPEN			0x01
1404 #define	FCP_EXCL			0x02
1405 #define	FCP_BUSY			0x04
1406 
1407 #define	LFA(x)				(x & 0xFFFF00)
1408 #define	FCP_SET				1
1409 #define	FCP_RESET			0
1410 
1411 /* init() and attach() wait timeout values (in usecs) */
1412 #define	FCP_INIT_WAIT_TIMEOUT		60000000	/* 60 seconds */
1413 #define	FCP_ATTACH_WAIT_TIMEOUT		10000000	/* 10 seconds */
1414 
1415 #ifdef	TRUE
1416 #undef	TRUE
1417 #endif
1418 #define	TRUE			1
1419 
1420 #ifdef	FALSE
1421 #undef	FALSE
1422 #endif
1423 #define	FALSE			0
1424 
1425 #define	UNDEFINED		-1
1426 
1427 /* for softstate */
1428 #define	FCP_INIT_ITEMS	5
1429 
1430 #ifdef	__cplusplus
1431 }
1432 #endif
1433 
1434 #endif	/* _FCPVAR_H */
1435