1*fcf3ce44SJohn Forte /*
2*fcf3ce44SJohn Forte  * CDDL HEADER START
3*fcf3ce44SJohn Forte  *
4*fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5*fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6*fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7*fcf3ce44SJohn Forte  *
8*fcf3ce44SJohn Forte  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*fcf3ce44SJohn Forte  * or http://www.opensolaris.org/os/licensing.
10*fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11*fcf3ce44SJohn Forte  * and limitations under the License.
12*fcf3ce44SJohn Forte  *
13*fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14*fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16*fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17*fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18*fcf3ce44SJohn Forte  *
19*fcf3ce44SJohn Forte  * CDDL HEADER END
20*fcf3ce44SJohn Forte  */
21*fcf3ce44SJohn Forte /*
22*fcf3ce44SJohn Forte  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*fcf3ce44SJohn Forte  * Use is subject to license terms.
24*fcf3ce44SJohn Forte  */
25*fcf3ce44SJohn Forte 
26*fcf3ce44SJohn Forte #ifndef	_FCSM_H
27*fcf3ce44SJohn Forte #define	_FCSM_H
28*fcf3ce44SJohn Forte 
29*fcf3ce44SJohn Forte 
30*fcf3ce44SJohn Forte 
31*fcf3ce44SJohn Forte #ifdef	__cplusplus
32*fcf3ce44SJohn Forte extern "C" {
33*fcf3ce44SJohn Forte #endif
34*fcf3ce44SJohn Forte 
35*fcf3ce44SJohn Forte #ifdef _KERNEL
36*fcf3ce44SJohn Forte 
37*fcf3ce44SJohn Forte /*
38*fcf3ce44SJohn Forte  * Message printing flags
39*fcf3ce44SJohn Forte  */
40*fcf3ce44SJohn Forte #define	SM_LOG			1
41*fcf3ce44SJohn Forte #define	SM_CONSOLE		2
42*fcf3ce44SJohn Forte #define	SM_LOG_AND_CONSOLE	3
43*fcf3ce44SJohn Forte 
44*fcf3ce44SJohn Forte /*
45*fcf3ce44SJohn Forte  * Debug levels
46*fcf3ce44SJohn Forte  */
47*fcf3ce44SJohn Forte #define	SMDL_TRACE	0x0001
48*fcf3ce44SJohn Forte #define	SMDL_IO		0x0002
49*fcf3ce44SJohn Forte #define	SMDL_ERR	0x0004
50*fcf3ce44SJohn Forte #define	SMDL_INFO	0x0008
51*fcf3ce44SJohn Forte 
52*fcf3ce44SJohn Forte #ifdef	DEBUG
53*fcf3ce44SJohn Forte #define	FCSM_DEBUG(level, args)	\
54*fcf3ce44SJohn Forte 	if (fcsm_debug & (level))	fcsm_display args
55*fcf3ce44SJohn Forte 
56*fcf3ce44SJohn Forte extern uint32_t fcsm_debug;
57*fcf3ce44SJohn Forte #else /* DEBUG */
58*fcf3ce44SJohn Forte #define	FCSM_DEBUG(level, args)
59*fcf3ce44SJohn Forte #endif /* DEBUG */
60*fcf3ce44SJohn Forte 
61*fcf3ce44SJohn Forte #define	FCSM_INIT_INSTANCES	8	/* # of instances for soft_state_init */
62*fcf3ce44SJohn Forte /*
63*fcf3ce44SJohn Forte  * Open flags
64*fcf3ce44SJohn Forte  */
65*fcf3ce44SJohn Forte #define	FCSM_IDLE		0x00
66*fcf3ce44SJohn Forte #define	FCSM_OPEN		0x01
67*fcf3ce44SJohn Forte #define	FCSM_EXCL		0x02
68*fcf3ce44SJohn Forte 
69*fcf3ce44SJohn Forte #define	FCSM_ELS_TIMEOUT	(20)	/* secs */
70*fcf3ce44SJohn Forte #define	FCSM_MS_TIMEOUT		(20)	/* secs */
71*fcf3ce44SJohn Forte 
72*fcf3ce44SJohn Forte #define	FCSM_OFFLINE_TICKER	(120)	/* secs */
73*fcf3ce44SJohn Forte 
74*fcf3ce44SJohn Forte /* Definitions for command retries */
75*fcf3ce44SJohn Forte #define	FCSM_MAX_CMD_RETRIES	5	/* Max retries in case of failure */
76*fcf3ce44SJohn Forte #define	FCSM_RETRY_INTERVAL	3	/* Retry interval in seconds */
77*fcf3ce44SJohn Forte #define	FCSM_RETRY_TICKER	1	/* Retry thread execution interval */
78*fcf3ce44SJohn Forte 
79*fcf3ce44SJohn Forte #define	FCSM_MAX_JOB_RETRIES	3	/* Max retries in case of job failure */
80*fcf3ce44SJohn Forte 
81*fcf3ce44SJohn Forte /*
82*fcf3ce44SJohn Forte  * fcsm_job - Job structure to issue commands using command thread
83*fcf3ce44SJohn Forte  */
84*fcf3ce44SJohn Forte typedef struct fcsm_job {
85*fcf3ce44SJohn Forte 	uint32_t	job_code;		/* Command code */
86*fcf3ce44SJohn Forte 	uint32_t	job_flags;		/* Command Flags */
87*fcf3ce44SJohn Forte 	int		job_port_instance;	/* port driver instance */
88*fcf3ce44SJohn Forte 	int		job_result;		/* job completion result */
89*fcf3ce44SJohn Forte 	opaque_t	job_arg;		/* Command Arguments */
90*fcf3ce44SJohn Forte 	opaque_t	job_caller_priv;	/* Caller private */
91*fcf3ce44SJohn Forte 	void		(*job_comp)(opaque_t, struct fcsm_job *, int);
92*fcf3ce44SJohn Forte 						/* completion func */
93*fcf3ce44SJohn Forte 	opaque_t	job_comp_arg;		/* Arg for completion func */
94*fcf3ce44SJohn Forte 	kmutex_t	job_mutex;		/* per command mutex */
95*fcf3ce44SJohn Forte 	ksema_t		job_sema;		/* To wait for completion */
96*fcf3ce44SJohn Forte 	struct fcsm_job	*job_next;		/* for linked list */
97*fcf3ce44SJohn Forte 	int		job_retry_count;	/* Retry count */
98*fcf3ce44SJohn Forte 	void		*job_priv;		/* for fcsm private use  */
99*fcf3ce44SJohn Forte 	uint32_t	job_priv_flags;		/* fcsm private flags */
100*fcf3ce44SJohn Forte } fcsm_job_t;
101*fcf3ce44SJohn Forte 
102*fcf3ce44SJohn Forte /*
103*fcf3ce44SJohn Forte  * fcsm_t - FCSM Structure for per port information
104*fcf3ce44SJohn Forte  */
105*fcf3ce44SJohn Forte typedef struct fcsm {
106*fcf3ce44SJohn Forte 	kmutex_t		sm_mutex;	/* mutex for protection */
107*fcf3ce44SJohn Forte 	struct fcsm		*sm_next;	/* for global linked list */
108*fcf3ce44SJohn Forte 	int			sm_sid;		/* FCA Port ID */
109*fcf3ce44SJohn Forte 	int			sm_instance;	/* fc port instance number */
110*fcf3ce44SJohn Forte 	uint32_t		sm_port_state;	/* FCA port state */
111*fcf3ce44SJohn Forte 	uint32_t		sm_port_top;	/* Port topology */
112*fcf3ce44SJohn Forte 	uint32_t		sm_state;	/* San Mgmt State information */
113*fcf3ce44SJohn Forte 	uint32_t		sm_flags;	/* San Mgmt Flags (see below) */
114*fcf3ce44SJohn Forte 	int			sm_ncmds;	/* # of pending commands */
115*fcf3ce44SJohn Forte 	int			sm_cb_count;	/* # callbacks in progress */
116*fcf3ce44SJohn Forte 	fc_ulp_port_info_t	sm_port_info;	/* FCA Port Information */
117*fcf3ce44SJohn Forte 	fcsm_job_t		*sm_job_head;	/* port's job queue head */
118*fcf3ce44SJohn Forte 	fcsm_job_t		*sm_job_tail;	/* port's job queue tail */
119*fcf3ce44SJohn Forte 	struct fcsm_cmd		*sm_retry_head;	/* cmd retry queue head */
120*fcf3ce44SJohn Forte 	struct fcsm_cmd		*sm_retry_tail;	/* cmd retry queue tail */
121*fcf3ce44SJohn Forte 	timeout_id_t		sm_retry_tid;	/* retry timer */
122*fcf3ce44SJohn Forte 	timeout_id_t		sm_offline_tid;	/* offline timer */
123*fcf3ce44SJohn Forte 	kcondvar_t		sm_job_cv;	/* cv for job processing */
124*fcf3ce44SJohn Forte 	uint32_t		sm_dev_count;	/* # of devices discovered */
125*fcf3ce44SJohn Forte 	fc_portmap_t		*sm_portmap;	/* device map */
126*fcf3ce44SJohn Forte 	kthread_t		*sm_thread;	/* per port job thread */
127*fcf3ce44SJohn Forte 	kmem_cache_t		*sm_cmd_cache;	/* per port fc packet cache */
128*fcf3ce44SJohn Forte 	la_els_logi_t		sm_ms_service_params;
129*fcf3ce44SJohn Forte 						/* Mgmt Server Login Params */
130*fcf3ce44SJohn Forte 	callb_cpr_t		sm_cpr_info;	/* CPR info */
131*fcf3ce44SJohn Forte } fcsm_t;
132*fcf3ce44SJohn Forte 
133*fcf3ce44SJohn Forte 
134*fcf3ce44SJohn Forte typedef struct fcsm_cmd {
135*fcf3ce44SJohn Forte 	fc_packet_t	*cmd_fp_pkt;
136*fcf3ce44SJohn Forte 	fcsm_job_t	*cmd_job;
137*fcf3ce44SJohn Forte 	fcsm_t		*cmd_fcsm;
138*fcf3ce44SJohn Forte 	int		cmd_retry_count;
139*fcf3ce44SJohn Forte 	int		cmd_retry_interval;
140*fcf3ce44SJohn Forte 	int		cmd_max_retries;
141*fcf3ce44SJohn Forte 	struct fcsm_cmd	*cmd_next;
142*fcf3ce44SJohn Forte 	void		(*cmd_comp)(struct fcsm_cmd *);
143*fcf3ce44SJohn Forte 	int		(*cmd_transport)(opaque_t, fc_packet_t *);
144*fcf3ce44SJohn Forte 	uint32_t	cmd_dma_flags;
145*fcf3ce44SJohn Forte 	fc_packet_t	cmd_fc_packet;
146*fcf3ce44SJohn Forte } fcsm_cmd_t;
147*fcf3ce44SJohn Forte 
148*fcf3ce44SJohn Forte /*
149*fcf3ce44SJohn Forte  * sm_flags in the per port FCSM Structure
150*fcf3ce44SJohn Forte  */
151*fcf3ce44SJohn Forte #define	FCSM_ATTACHING			0x0001
152*fcf3ce44SJohn Forte #define	FCSM_ATTACHED			0x0002
153*fcf3ce44SJohn Forte #define	FCSM_DETACHING			0x0004
154*fcf3ce44SJohn Forte #define	FCSM_DETACHED			0x0008
155*fcf3ce44SJohn Forte #define	FCSM_SUSPENDED			0x0010
156*fcf3ce44SJohn Forte #define	FCSM_POWER_DOWN			0x0020
157*fcf3ce44SJohn Forte #define	FCSM_RESTORE_RETRY_TIMEOUT	0x0040
158*fcf3ce44SJohn Forte #define	FCSM_RESTORE_OFFLINE_TIMEOUT	0x0080
159*fcf3ce44SJohn Forte #define	FCSM_RETRY_TIMER_ACTIVE		0x0100
160*fcf3ce44SJohn Forte #define	FCSM_SERIALIZE_JOBTHREAD	0x0200
161*fcf3ce44SJohn Forte #define	FCSM_CMD_RETRY_Q_SUSPENDED	0x0400
162*fcf3ce44SJohn Forte #define	FCSM_PORT_OFFLINE		0x0800
163*fcf3ce44SJohn Forte #define	FCSM_LINK_DOWN			0x1000
164*fcf3ce44SJohn Forte #define	FCSM_MGMT_SERVER_LOGGED_IN	0x2000
165*fcf3ce44SJohn Forte #define	FCSM_MGMT_SERVER_LOGIN_IN_PROG	0x4000
166*fcf3ce44SJohn Forte 
167*fcf3ce44SJohn Forte /* Command flags for Job structure */
168*fcf3ce44SJohn Forte #define	FCSM_JOBFLAG_SYNC		0x01
169*fcf3ce44SJohn Forte #define	FCSM_JOBFLAG_ASYNC		0x02
170*fcf3ce44SJohn Forte #define	FCSM_JOBFLAG_SERIALIZE		0x04
171*fcf3ce44SJohn Forte #define	FCSM_JOBFLAG_CTHEADER_BE	0X08
172*fcf3ce44SJohn Forte 
173*fcf3ce44SJohn Forte /* Command codes */
174*fcf3ce44SJohn Forte #define	FCSM_JOB_NONE			0x00
175*fcf3ce44SJohn Forte #define	FCSM_JOB_THREAD_SHUTDOWN	0x01
176*fcf3ce44SJohn Forte #define	FCSM_JOB_LOGIN_NAME_SERVER	0x02
177*fcf3ce44SJohn Forte #define	FCSM_JOB_LOGIN_MGMT_SERVER	0x03
178*fcf3ce44SJohn Forte #define	FCSM_JOB_CT_PASSTHRU		0x04
179*fcf3ce44SJohn Forte 
180*fcf3ce44SJohn Forte /* Private flags for command */
181*fcf3ce44SJohn Forte #define	FCSM_JOB_PRIV_WAIT_FOR_LOGIN	0x01
182*fcf3ce44SJohn Forte #define	FCSM_JOB_PRIV_LOGIN_IN_PROG	0x02
183*fcf3ce44SJohn Forte 
184*fcf3ce44SJohn Forte /* Command DMA Flags */
185*fcf3ce44SJohn Forte #define	FCSM_CF_CMD_VALID_DMA_MEM	0x01
186*fcf3ce44SJohn Forte #define	FCSM_CF_CMD_VALID_DMA_BIND	0x02
187*fcf3ce44SJohn Forte #define	FCSM_CF_RESP_VALID_DMA_MEM	0x04
188*fcf3ce44SJohn Forte #define	FCSM_CF_RESP_VALID_DMA_BIND	0x08
189*fcf3ce44SJohn Forte 
190*fcf3ce44SJohn Forte #define	FCSM_INIT_CMD(cmd, job, tran_flags, tran_type, max_retries, func) { \
191*fcf3ce44SJohn Forte 	(cmd)->cmd_job = (job); \
192*fcf3ce44SJohn Forte 	(cmd)->cmd_fc_packet.pkt_tran_flags = (tran_flags); \
193*fcf3ce44SJohn Forte 	(cmd)->cmd_fc_packet.pkt_tran_type = (tran_type); \
194*fcf3ce44SJohn Forte 	(cmd)->cmd_max_retries = max_retries; \
195*fcf3ce44SJohn Forte 	(cmd)->cmd_comp = func; \
196*fcf3ce44SJohn Forte }
197*fcf3ce44SJohn Forte 
198*fcf3ce44SJohn Forte /*
199*fcf3ce44SJohn Forte  * Macros to address endian issues
200*fcf3ce44SJohn Forte  */
201*fcf3ce44SJohn Forte #define	FCSM_RD8(acchandle, addr)       \
202*fcf3ce44SJohn Forte 	ddi_get8((acchandle), (uint8_t *)(addr))
203*fcf3ce44SJohn Forte #define	FCSM_RD16(acchandle, addr)      \
204*fcf3ce44SJohn Forte 	ddi_get16((acchandle), (uint16_t *)(addr))
205*fcf3ce44SJohn Forte #define	FCSM_RD32(acchandle, addr)      \
206*fcf3ce44SJohn Forte 	ddi_get32((acchandle), (uint32_t *)(addr))
207*fcf3ce44SJohn Forte #define	FCSM_RD64(acchandle, addr)      \
208*fcf3ce44SJohn Forte 	ddi_get64((acchandle), (uint64_t *)(addr))
209*fcf3ce44SJohn Forte 
210*fcf3ce44SJohn Forte #define	FCSM_WR8(acchandle, addr, val)  \
211*fcf3ce44SJohn Forte 	ddi_put8((acchandle), (uint8_t *)(addr), (uint8_t)(val))
212*fcf3ce44SJohn Forte #define	FCSM_WR16(acchandle, addr, val) \
213*fcf3ce44SJohn Forte 	ddi_put16((acchandle), (uint16_t *)(addr), (uint16_t)(val))
214*fcf3ce44SJohn Forte #define	FCSM_WR32(acchandle, addr, val) \
215*fcf3ce44SJohn Forte 	ddi_put32((acchandle), (uint32_t *)(addr), (uint32_t)(val))
216*fcf3ce44SJohn Forte #define	FCSM_WR64(acchandle, addr, val) \
217*fcf3ce44SJohn Forte 	ddi_put64((acchandle), (uint64_t *)(addr), (uint64_t)(val))
218*fcf3ce44SJohn Forte 
219*fcf3ce44SJohn Forte #define	FCSM_REP_RD(acchandle, hostaddr, devaddr, cnt)  \
220*fcf3ce44SJohn Forte 	ddi_rep_get8((acchandle), (uint8_t *)(hostaddr), (uint8_t *)(devaddr),\
221*fcf3ce44SJohn Forte 	    (size_t)(cnt), DDI_DEV_AUTOINCR)
222*fcf3ce44SJohn Forte #define	FCSM_REP_RD32(acchandle, hostaddr, devaddr, cnt)        \
223*fcf3ce44SJohn Forte 	ddi_rep_get32((acchandle), (uint32_t *)(hostaddr),      \
224*fcf3ce44SJohn Forte 	    (uint32_t *)(devaddr), ((size_t)(cnt)) >> 2, DDI_DEV_AUTOINCR)
225*fcf3ce44SJohn Forte 
226*fcf3ce44SJohn Forte #define	FCSM_REP_WR(acchandle, hostaddr, devaddr, cnt)  \
227*fcf3ce44SJohn Forte 	ddi_rep_put8((acchandle), (uint8_t *)(hostaddr), (uint8_t *)(devaddr),\
228*fcf3ce44SJohn Forte 	    (size_t)(cnt), DDI_DEV_AUTOINCR)
229*fcf3ce44SJohn Forte #define	FCSM_REP_WR32(acchandle, hostaddr, devaddr, cnt)        \
230*fcf3ce44SJohn Forte 	ddi_rep_put32((acchandle), (uint32_t *)(hostaddr),\
231*fcf3ce44SJohn Forte 	    (uint32_t *)(devaddr), ((size_t)(cnt)) >> 2, DDI_DEV_AUTOINCR)
232*fcf3ce44SJohn Forte 
233*fcf3ce44SJohn Forte /*
234*fcf3ce44SJohn Forte  * Macros to perform DMA Sync
235*fcf3ce44SJohn Forte  */
236*fcf3ce44SJohn Forte #define	FCSM_SYNC_FOR_DEV(dmahandle, offset, length)    \
237*fcf3ce44SJohn Forte 	(void) ddi_dma_sync((dmahandle), (offset),\
238*fcf3ce44SJohn Forte 	    (size_t)(length), DDI_DMA_SYNC_FORDEV)
239*fcf3ce44SJohn Forte #define	FCSM_SYNC_FOR_KERNEL(dmahandle, offset, length) \
240*fcf3ce44SJohn Forte 	(void) ddi_dma_sync((acchandle), (offset),\
241*fcf3ce44SJohn Forte 	    (length), DDI_DMA_SYNC_FORKERNEL)
242*fcf3ce44SJohn Forte 
243*fcf3ce44SJohn Forte #endif /* _KERNEL */
244*fcf3ce44SJohn Forte 
245*fcf3ce44SJohn Forte /*
246*fcf3ce44SJohn Forte  * IOCTL Definitions
247*fcf3ce44SJohn Forte  */
248*fcf3ce44SJohn Forte typedef struct fc_ct_aiu {
249*fcf3ce44SJohn Forte 	fc_ct_header_t	aiu_header;
250*fcf3ce44SJohn Forte 	char		aiu_payload[1];
251*fcf3ce44SJohn Forte 	/* aiu_payload can be up to 'm' bytes (arbitrary length) */
252*fcf3ce44SJohn Forte } fc_ct_aiu_t;
253*fcf3ce44SJohn Forte 
254*fcf3ce44SJohn Forte #define	FCSMIO			('S' << 8)
255*fcf3ce44SJohn Forte #define	FCSMIO_CMD		(FCSMIO | 2000)
256*fcf3ce44SJohn Forte 
257*fcf3ce44SJohn Forte #define	FCSMIO_SUB_CMD		('Y' << 8)
258*fcf3ce44SJohn Forte #define	FCSMIO_CT_CMD		(FCSMIO_SUB_CMD + 0x01)
259*fcf3ce44SJohn Forte #define	FCSMIO_ADAPTER_LIST	(FCSMIO_SUB_CMD + 0x02)
260*fcf3ce44SJohn Forte #define	FCSMIO_FIND_ADAPTER	(FCSMIO_SUB_CMD + 0x03)
261*fcf3ce44SJohn Forte 
262*fcf3ce44SJohn Forte #define	FCSM_MAX_CT_SIZE	(65536)		/* 64K */
263*fcf3ce44SJohn Forte 
264*fcf3ce44SJohn Forte /* Management Server - Fabric Configuration Server Commands */
265*fcf3ce44SJohn Forte #define	MS_CS_GTIN	0x0100	/* Get Topology Information */
266*fcf3ce44SJohn Forte #define	MS_CS_GIEL	0x0101	/* Get Interconnect Element List */
267*fcf3ce44SJohn Forte #define	MS_CS_GIET	0x0111	/* Get Interconnect Element Type */
268*fcf3ce44SJohn Forte #define	MS_CS_GDID	0x0112	/* Get Domain Identifier */
269*fcf3ce44SJohn Forte #define	MS_CS_GMID	0x0113	/* Get Management Identifier */
270*fcf3ce44SJohn Forte #define	MS_CS_GFN	0x0114	/* Get Fabric Name */
271*fcf3ce44SJohn Forte #define	MS_CS_GIELN	0x0115	/* Get Interconnect Element Logical Name */
272*fcf3ce44SJohn Forte #define	MS_CS_GMAL	0x0116	/* Get Management Address List */
273*fcf3ce44SJohn Forte #define	MS_CS_GIEIL	0x0117	/* Get Interconnect Element Information List */
274*fcf3ce44SJohn Forte #define	MS_CS_GPL	0x0118	/* Get Port List */
275*fcf3ce44SJohn Forte #define	MS_CS_GPT	0x0121	/* Get Port Type */
276*fcf3ce44SJohn Forte #define	MS_CS_GPPN	0x0122	/* Get Physical Port Number */
277*fcf3ce44SJohn Forte #define	MS_CS_GAPNL	0x0124	/* Get Attached Port Name List */
278*fcf3ce44SJohn Forte #define	MS_CS_GPS	0x0126	/* Get Port State */
279*fcf3ce44SJohn Forte #define	MS_CS_GATIN	0x0128	/* Get Attached Topology Information */
280*fcf3ce44SJohn Forte #define	MS_CS_GPLNL	0x0191	/* Get Platform Node Name List */
281*fcf3ce44SJohn Forte #define	MS_CS_GPLT	0x0192	/* Get Platform Type */
282*fcf3ce44SJohn Forte #define	MS_CS_GPLML	0x0193	/* Get Platform Management Address List */
283*fcf3ce44SJohn Forte #define	MS_CS_GNPL	0x01a1	/* Get Platform Name - Node Name */
284*fcf3ce44SJohn Forte #define	MS_CS_GPNL	0x01a2	/* Get Platform Name List */
285*fcf3ce44SJohn Forte #define	MS_CS_GNID	0x01b1	/* Get Node Identification Data - Node Name */
286*fcf3ce44SJohn Forte #define	MS_CS_RIELN	0x0215	/* Register Interconnect Element Logical Name */
287*fcf3ce44SJohn Forte #define	MS_CS_RPL	0x0280	/* Register Platform */
288*fcf3ce44SJohn Forte #define	MS_CS_RPLN	0x0291	/* Register Platform Name */
289*fcf3ce44SJohn Forte #define	MS_CS_RPLT	0x0292	/* Register Platform Type */
290*fcf3ce44SJohn Forte #define	MS_CS_RPLM	0x0293	/* Register Platform Management Address */
291*fcf3ce44SJohn Forte #define	MS_CS_DPL	0x0380	/* Deregister Platform */
292*fcf3ce44SJohn Forte #define	MS_CS_DPLN	0x0391	/* Deregister Platform Node Name */
293*fcf3ce44SJohn Forte #define	MS_CS_DPLML	0x0393	/* Deregister Platform Management Addr List */
294*fcf3ce44SJohn Forte 
295*fcf3ce44SJohn Forte #ifdef _KERNEL
296*fcf3ce44SJohn Forte 
297*fcf3ce44SJohn Forte /*
298*fcf3ce44SJohn Forte  * Driver entry point functions
299*fcf3ce44SJohn Forte  */
300*fcf3ce44SJohn Forte static int	fcsm_attach(dev_info_t *, ddi_attach_cmd_t);
301*fcf3ce44SJohn Forte static int	fcsm_detach(dev_info_t *, ddi_detach_cmd_t);
302*fcf3ce44SJohn Forte static int	fcsm_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
303*fcf3ce44SJohn Forte static int	fcsm_open(dev_t *, int, int, cred_t *);
304*fcf3ce44SJohn Forte static int	fcsm_close(dev_t, int, int, cred_t *);
305*fcf3ce44SJohn Forte static int	fcsm_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
306*fcf3ce44SJohn Forte 
307*fcf3ce44SJohn Forte /*
308*fcf3ce44SJohn Forte  * FC Transport functions
309*fcf3ce44SJohn Forte  */
310*fcf3ce44SJohn Forte static int	fcsm_port_attach(opaque_t, fc_ulp_port_info_t *,
311*fcf3ce44SJohn Forte 		    fc_attach_cmd_t, uint32_t);
312*fcf3ce44SJohn Forte static int	fcsm_port_detach(opaque_t, fc_ulp_port_info_t *,
313*fcf3ce44SJohn Forte 		    fc_detach_cmd_t);
314*fcf3ce44SJohn Forte static int	fcsm_port_ioctl(opaque_t, opaque_t, dev_t, int, intptr_t,
315*fcf3ce44SJohn Forte 		    int, cred_t *, int *, uint32_t);
316*fcf3ce44SJohn Forte static void	fcsm_statec_cb(opaque_t, opaque_t, uint32_t, uint32_t,
317*fcf3ce44SJohn Forte 		    fc_portmap_t *, uint32_t, uint32_t);
318*fcf3ce44SJohn Forte static int	fcsm_els_cb(opaque_t, opaque_t, fc_unsol_buf_t *, uint32_t);
319*fcf3ce44SJohn Forte static int	fcsm_data_cb(opaque_t, opaque_t, fc_unsol_buf_t *, uint32_t);
320*fcf3ce44SJohn Forte 
321*fcf3ce44SJohn Forte /*
322*fcf3ce44SJohn Forte  * Internal functions
323*fcf3ce44SJohn Forte  */
324*fcf3ce44SJohn Forte static int	fcsm_handle_port_attach(fc_ulp_port_info_t *, uint32_t, int);
325*fcf3ce44SJohn Forte static int	fcsm_handle_port_resume(opaque_t, fc_ulp_port_info_t *,
326*fcf3ce44SJohn Forte 		    fc_attach_cmd_t, uint32_t, fcsm_t *);
327*fcf3ce44SJohn Forte static int	fcsm_handle_port_detach(fc_ulp_port_info_t *, fcsm_t *,
328*fcf3ce44SJohn Forte 		    fc_detach_cmd_t);
329*fcf3ce44SJohn Forte static void	fcsm_suspend_port(fcsm_t *);
330*fcf3ce44SJohn Forte static void	fcsm_resume_port(fcsm_t *);
331*fcf3ce44SJohn Forte static void	fcsm_cleanup_port(fcsm_t *);
332*fcf3ce44SJohn Forte static void	fcsm_offline_timeout(void *);
333*fcf3ce44SJohn Forte static int	fcsm_fciocmd(intptr_t, int, cred_t *, fcio_t *);
334*fcf3ce44SJohn Forte static int	fcsm_fcio_copyout(fcio_t *, intptr_t, int);
335*fcf3ce44SJohn Forte static int	fcsm_job_cache_constructor(void *, void *, int);
336*fcf3ce44SJohn Forte static void	fcsm_job_cache_destructor(void *, void *);
337*fcf3ce44SJohn Forte static fcsm_job_t *fcsm_alloc_job(int);
338*fcf3ce44SJohn Forte static void	fcsm_dealloc_job(fcsm_job_t *);
339*fcf3ce44SJohn Forte static void	fcsm_init_job(fcsm_job_t *, int, uint32_t, uint32_t, opaque_t,
340*fcf3ce44SJohn Forte 		    opaque_t, void (*comp)(opaque_t, fcsm_job_t *, int),
341*fcf3ce44SJohn Forte 		    opaque_t);
342*fcf3ce44SJohn Forte static int	fcsm_process_job(fcsm_job_t *, int);
343*fcf3ce44SJohn Forte static void	fcsm_enque_job(fcsm_t *, fcsm_job_t *, int);
344*fcf3ce44SJohn Forte static fcsm_job_t *fcsm_deque_job(fcsm_t *);
345*fcf3ce44SJohn Forte static int	fcsm_cmd_cache_constructor(void *, void *, int);
346*fcf3ce44SJohn Forte static void	fcsm_cmd_cache_destructor(void *, void *);
347*fcf3ce44SJohn Forte static fcsm_cmd_t	*fcsm_alloc_cmd(fcsm_t *, uint32_t, uint32_t, int);
348*fcf3ce44SJohn Forte static void	fcsm_free_cmd_dma(fcsm_cmd_t *);
349*fcf3ce44SJohn Forte static void	fcsm_job_thread(fcsm_t *);
350*fcf3ce44SJohn Forte static int	fcsm_retry_job(fcsm_t *fcsm, fcsm_job_t *job);
351*fcf3ce44SJohn Forte static void	fcsm_jobdone(fcsm_job_t *);
352*fcf3ce44SJohn Forte static void	fcsm_ct_init(fcsm_t *, fcsm_cmd_t *, fc_ct_aiu_t *, size_t,
353*fcf3ce44SJohn Forte 		    void (*comp_func)());
354*fcf3ce44SJohn Forte static void	fcsm_ct_intr(fcsm_cmd_t *);
355*fcf3ce44SJohn Forte static void	fcsm_job_ct_passthru(fcsm_job_t *);
356*fcf3ce44SJohn Forte static int	fcsm_login_and_process_job(fcsm_t *, fcsm_job_t *);
357*fcf3ce44SJohn Forte static void	fcsm_login_ms_comp(opaque_t, fcsm_job_t *, int);
358*fcf3ce44SJohn Forte static void	fcsm_els_init(fcsm_cmd_t *, uint32_t);
359*fcf3ce44SJohn Forte static int	fcsm_xlogi_init(fcsm_t *, fcsm_cmd_t *, uint32_t,
360*fcf3ce44SJohn Forte 		    void (*comp_func)(), uchar_t);
361*fcf3ce44SJohn Forte static void	fcsm_xlogi_intr(fcsm_cmd_t *);
362*fcf3ce44SJohn Forte static void	fcsm_job_login_mgmt_server(fcsm_job_t *);
363*fcf3ce44SJohn Forte int		fcsm_ct_passthru(int, fcio_t *, int, int,
364*fcf3ce44SJohn Forte 		    void (*func)(fcio_t *));
365*fcf3ce44SJohn Forte static void	fcsm_ct_passthru_comp(opaque_t, fcsm_job_t *, int);
366*fcf3ce44SJohn Forte static void	fcsm_pkt_common_intr(fc_packet_t *);
367*fcf3ce44SJohn Forte static int	fcsm_issue_cmd(fcsm_cmd_t *);
368*fcf3ce44SJohn Forte static int	fcsm_retry_cmd(fcsm_cmd_t *);
369*fcf3ce44SJohn Forte static void	fcsm_enque_cmd(fcsm_t *, fcsm_cmd_t *);
370*fcf3ce44SJohn Forte static fcsm_cmd_t *fcsm_deque_cmd(fcsm_t *);
371*fcf3ce44SJohn Forte static void	fcsm_retry_timeout(void *);
372*fcf3ce44SJohn Forte static void	fcsm_force_port_detach_all(void);
373*fcf3ce44SJohn Forte 
374*fcf3ce44SJohn Forte 
375*fcf3ce44SJohn Forte /*
376*fcf3ce44SJohn Forte  * Utility functions
377*fcf3ce44SJohn Forte  */
378*fcf3ce44SJohn Forte static void	fcsm_disp_devlist(fcsm_t *, fc_portmap_t *, uint32_t);
379*fcf3ce44SJohn Forte 
380*fcf3ce44SJohn Forte static void	fcsm_display(int, int, fcsm_t *,
381*fcf3ce44SJohn Forte 		    fc_packet_t *, const char *, ...);
382*fcf3ce44SJohn Forte int		fcsm_pkt_state_to_rval(uchar_t, uint32_t);
383*fcf3ce44SJohn Forte caddr_t		fcsm_port_state_to_str(uint32_t);
384*fcf3ce44SJohn Forte caddr_t		fcsm_topology_to_str(uint32_t);
385*fcf3ce44SJohn Forte static caddr_t	fcsm_dev_type_to_str(uint32_t);
386*fcf3ce44SJohn Forte 
387*fcf3ce44SJohn Forte 
388*fcf3ce44SJohn Forte #endif /* _KERNEL */
389*fcf3ce44SJohn Forte 
390*fcf3ce44SJohn Forte 
391*fcf3ce44SJohn Forte #ifdef	__cplusplus
392*fcf3ce44SJohn Forte }
393*fcf3ce44SJohn Forte #endif
394*fcf3ce44SJohn Forte 
395*fcf3ce44SJohn Forte #endif /* _FCSM_H */
396