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