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