xref: /illumos-gate/usr/src/uts/sun/sys/socalvar.h (revision 3db86aab)
1*3db86aabSstevel /*
2*3db86aabSstevel  * CDDL HEADER START
3*3db86aabSstevel  *
4*3db86aabSstevel  * The contents of this file are subject to the terms of the
5*3db86aabSstevel  * Common Development and Distribution License (the "License").
6*3db86aabSstevel  * You may not use this file except in compliance with the License.
7*3db86aabSstevel  *
8*3db86aabSstevel  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*3db86aabSstevel  * or http://www.opensolaris.org/os/licensing.
10*3db86aabSstevel  * See the License for the specific language governing permissions
11*3db86aabSstevel  * and limitations under the License.
12*3db86aabSstevel  *
13*3db86aabSstevel  * When distributing Covered Code, include this CDDL HEADER in each
14*3db86aabSstevel  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*3db86aabSstevel  * If applicable, add the following below this CDDL HEADER, with the
16*3db86aabSstevel  * fields enclosed by brackets "[]" replaced with your own identifying
17*3db86aabSstevel  * information: Portions Copyright [yyyy] [name of copyright owner]
18*3db86aabSstevel  *
19*3db86aabSstevel  * CDDL HEADER END
20*3db86aabSstevel  */
21*3db86aabSstevel /*
22*3db86aabSstevel  * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
23*3db86aabSstevel  * Use is subject to license terms.
24*3db86aabSstevel  */
25*3db86aabSstevel 
26*3db86aabSstevel #ifndef _SYS_SOCALVAR_H
27*3db86aabSstevel #define	_SYS_SOCALVAR_H
28*3db86aabSstevel 
29*3db86aabSstevel #pragma ident	"%Z%%M%	%I%	%E% SMI"
30*3db86aabSstevel 
31*3db86aabSstevel #ifdef __cplusplus
32*3db86aabSstevel extern "C" {
33*3db86aabSstevel #endif
34*3db86aabSstevel 
35*3db86aabSstevel #include <sys/id32.h>
36*3db86aabSstevel 
37*3db86aabSstevel /*
38*3db86aabSstevel  * socalvar.h - SOC+ Driver data struct definitions
39*3db86aabSstevel  */
40*3db86aabSstevel 
41*3db86aabSstevel /*
42*3db86aabSstevel  * Define default name and # of SOC+s to allocate to the system
43*3db86aabSstevel  */
44*3db86aabSstevel 
45*3db86aabSstevel #define	SOCAL_PORTA_NAME	"0"	/* node for port a */
46*3db86aabSstevel #define	SOCAL_PORTB_NAME	"1"	/* node for port b */
47*3db86aabSstevel #define	SOCAL_NT_PORT		NULL
48*3db86aabSstevel #define	SOCAL_INIT_ITEMS	5
49*3db86aabSstevel 
50*3db86aabSstevel /*
51*3db86aabSstevel  * Defines for the Circular Queues
52*3db86aabSstevel  */
53*3db86aabSstevel #define	SOCAL_MAX_CQ_ENTRIES	256	/* Maximum number of CQ entries. */
54*3db86aabSstevel #define	SOCAL_CQ_SIZE (sizeof (cqe_t) * SOC_MAX_CQ_ENTRIES)
55*3db86aabSstevel 
56*3db86aabSstevel #define	SOCAL_SMALL_CQ_ENTRIES	8	/* Number of CQ entries for a small Q */
57*3db86aabSstevel 
58*3db86aabSstevel #define	SOCAL_N_CQS		4	/* Number of queues we use */
59*3db86aabSstevel #define	SOCAL_HW_N_CQS		4	/* Number of queues the hardware has */
60*3db86aabSstevel #define	SOCAL_CQ_ALIGN		64	/* alignment boundary */
61*3db86aabSstevel 
62*3db86aabSstevel #define	SOCAL_TAKE_CORE		0x1
63*3db86aabSstevel #define	SOCAL_FAILED_LIP	0x2
64*3db86aabSstevel 
65*3db86aabSstevel /*
66*3db86aabSstevel  * Misc. Macros
67*3db86aabSstevel  */
68*3db86aabSstevel #define	SOCAL_POOL_SIZE		2112
69*3db86aabSstevel #define	SOCAL_SVC_LENGTH	80
70*3db86aabSstevel 
71*3db86aabSstevel #define	FABRIC_FLAG	1
72*3db86aabSstevel #define	NPORT_FLAG	2
73*3db86aabSstevel 
74*3db86aabSstevel #define	FCIO_DIAG_LBTFQ		(FIOC|203)
75*3db86aabSstevel #define	SOC_DIAG_LBTFQ		0x0a
76*3db86aabSstevel #define	PORT_LBF_PENDING	0x00100000
77*3db86aabSstevel #define	SOCAL_LBF_TIMEOUT	15000000 /* usec */
78*3db86aabSstevel 
79*3db86aabSstevel /* Macros to speed handling of 32-bit IDs */
80*3db86aabSstevel #define	SOCAL_ID_GET(x, w)	id32_alloc((x), (w))
81*3db86aabSstevel #define	SOCAL_ID_LOOKUP(x)	id32_lookup((x))
82*3db86aabSstevel #define	SOCAL_ID_FREE(x)	id32_free((x))
83*3db86aabSstevel 
84*3db86aabSstevel typedef	struct flb_hdr {
85*3db86aabSstevel 	uint_t max_length;
86*3db86aabSstevel 	uint_t length;
87*3db86aabSstevel } flb_hdr_t;
88*3db86aabSstevel 
89*3db86aabSstevel struct socal_state;
90*3db86aabSstevel 
91*3db86aabSstevel /*
92*3db86aabSstevel  * SOC UNIX circular queue descriptor.
93*3db86aabSstevel  */
94*3db86aabSstevel 
95*3db86aabSstevel typedef struct socal_kernel_cq {
96*3db86aabSstevel 	kmutex_t	skc_mtx;	/* MT lock for CQ manipulation  */
97*3db86aabSstevel 	kcondvar_t	skc_cv;		/* cond var for CQ manipulation. */
98*3db86aabSstevel 	ddi_dma_handle_t skc_dhandle;	/* DDI DMA handle to CQ. */
99*3db86aabSstevel 	ddi_dma_cookie_t skc_dcookie;	/* DDI DMA Cookie. */
100*3db86aabSstevel 	ddi_acc_handle_t skc_acchandle;	/* DDI DMA access handle */
101*3db86aabSstevel 	soc_cq_t	*skc_xram_cqdesc; /* Pointer to XRAM CQ desc */
102*3db86aabSstevel 	caddr_t		skc_cq_raw;	/* Pointer to unaligned CQ mem pool */
103*3db86aabSstevel 	cqe_t		*skc_cq;	/* Pointer to CQ memory pool. */
104*3db86aabSstevel 	uchar_t		skc_in;		/* Current Input pointer. */
105*3db86aabSstevel 	uchar_t		skc_out;	/* Current Input pointer. */
106*3db86aabSstevel 	uchar_t		skc_last_index;	/* Last cq index. */
107*3db86aabSstevel 	uchar_t		skc_seqno;	/* Current Go Around in CQ. */
108*3db86aabSstevel 	uchar_t		skc_full;	/* Indication of full. */
109*3db86aabSstevel 	uchar_t		skc_saved_out;	/* Current Input pointer. */
110*3db86aabSstevel 	uchar_t		skc_saved_seqno;	/* Current Go Around in CQ. */
111*3db86aabSstevel 	timeout_id_t	deferred_intr_timeoutid;
112*3db86aabSstevel 	struct fcal_packet	*skc_overflowh; /* cq overflow list */
113*3db86aabSstevel 	struct fcal_packet	*skc_overflowt;
114*3db86aabSstevel 	struct socal_state	*skc_socalp;
115*3db86aabSstevel } socal_kcq_t;
116*3db86aabSstevel 
117*3db86aabSstevel /*
118*3db86aabSstevel  * Values for skc_full
119*3db86aabSstevel  */
120*3db86aabSstevel #define	SOCAL_SKC_FULL	1
121*3db86aabSstevel #define	SOCAL_SKC_SLEEP	2
122*3db86aabSstevel 
123*3db86aabSstevel /*
124*3db86aabSstevel  * State change callback routine descriptor
125*3db86aabSstevel  *
126*3db86aabSstevel  * There is one entry in this list for each hba that is attached
127*3db86aabSstevel  * to this port.
128*3db86aabSstevel  * This structure will need to be mutex protected when parallel
129*3db86aabSstevel  * attaches are supported.
130*3db86aabSstevel  */
131*3db86aabSstevel typedef struct socal_unsol_cb {
132*3db86aabSstevel 	struct socal_unsol_cb	*next;
133*3db86aabSstevel 	uchar_t			type;
134*3db86aabSstevel 	void			(*statec_cb)(void *, uint32_t);
135*3db86aabSstevel 	void			(*els_cb)(void *, cqe_t *, caddr_t);
136*3db86aabSstevel 	void			(*data_cb)(void *, cqe_t *, caddr_t);
137*3db86aabSstevel 	void			*arg;
138*3db86aabSstevel } socal_unsol_cb_t;
139*3db86aabSstevel 
140*3db86aabSstevel /*
141*3db86aabSstevel  * SOC+ port status decriptor.
142*3db86aabSstevel  */
143*3db86aabSstevel typedef struct socal_port {
144*3db86aabSstevel 	uint32_t		sp_status;	/* port status */
145*3db86aabSstevel 	struct socal_state	*sp_board;	/* hardware for instance */
146*3db86aabSstevel 
147*3db86aabSstevel 	uint32_t		sp_src_id;	/* Our nport id */
148*3db86aabSstevel 	uint32_t		sp_port;	/* Our physical port (0, 1) */
149*3db86aabSstevel 	la_wwn_t		sp_p_wwn;	/* Our Port WorldWide Name */
150*3db86aabSstevel 
151*3db86aabSstevel 	socal_unsol_cb_t	*sp_unsol_cb;	/* Callback for state change */
152*3db86aabSstevel 
153*3db86aabSstevel 	uint32_t		sp_open;	/* open count */
154*3db86aabSstevel 
155*3db86aabSstevel 	kmutex_t		sp_mtx;		/* Per port mutex */
156*3db86aabSstevel 	kcondvar_t		sp_cv;		/* Per port condvariable */
157*3db86aabSstevel 	fcal_transport_t	*sp_transport;	/* transport structure */
158*3db86aabSstevel 
159*3db86aabSstevel 	uint32_t		sp_hard_alpa;	/* Our optional Hard AL_PA */
160*3db86aabSstevel 
161*3db86aabSstevel 	uint32_t		sp_lilpmap_valid;  /* lilp map cache valid  */
162*3db86aabSstevel 	fcal_lilp_map_t		sp_lilpmap;  /* lilp map cache */
163*3db86aabSstevel } socal_port_t;
164*3db86aabSstevel 
165*3db86aabSstevel #define	PORT_FABRIC_PRESENT	0x00000001
166*3db86aabSstevel #define	PORT_OFFLINE		0x00000002
167*3db86aabSstevel #define	NPORT_LOGIN_SUCCESS	0x00000004
168*3db86aabSstevel #define	PORT_LOGIN_ACTIVE	0x00000008
169*3db86aabSstevel #define	PORT_LOGIN_RECOVERY	0x00000010
170*3db86aabSstevel #define	PORT_ONLINE_LOOP	0x00000020
171*3db86aabSstevel #define	PORT_ONLINE		0x00000040
172*3db86aabSstevel #define	PORT_STATUS_FLAG	0x00000080
173*3db86aabSstevel #define	PORT_STATUS_MASK	0x000000ff
174*3db86aabSstevel #define	PORT_OPEN		0x00000100
175*3db86aabSstevel #define	PORT_CHILD_INIT		0x00000200
176*3db86aabSstevel #define	PORT_TARGET_MODE	0x00000400
177*3db86aabSstevel #define	PORT_LILP_PENDING	0x00001000
178*3db86aabSstevel #define	PORT_LIP_PENDING	0x00002000
179*3db86aabSstevel #define	PORT_ABORT_PENDING	0x00004000
180*3db86aabSstevel #define	PORT_ELS_PENDING	0x00008000
181*3db86aabSstevel #define	PORT_BYPASS_PENDING	0x00010000
182*3db86aabSstevel #define	PORT_OFFLINE_PENDING	0x00020000
183*3db86aabSstevel #define	PORT_ADISC_PENDING	0x00040000
184*3db86aabSstevel #define	PORT_RLS_PENDING	0x00080000
185*3db86aabSstevel #define	PORT_DISABLED		0x00100000
186*3db86aabSstevel 
187*3db86aabSstevel 
188*3db86aabSstevel #define	SOC_TIMEOUT_DELAY(secs, delay)  (secs * (1000000 / delay))
189*3db86aabSstevel #define	SOCAL_NOINTR_POLL_DELAY_TIME	1000    /* usec */
190*3db86aabSstevel 
191*3db86aabSstevel #define	SOCAL_LILP_TIMEOUT		10000000 /* usec */
192*3db86aabSstevel #define	SOCAL_LIP_TIMEOUT		30000000 /* usec */
193*3db86aabSstevel #define	SOCAL_ABORT_TIMEOUT		10000000 /* usec */
194*3db86aabSstevel #define	SOCAL_BYPASS_TIMEOUT		5000000	/* usec */
195*3db86aabSstevel #define	SOCAL_OFFLINE_TIMEOUT		5000000	/* usec */
196*3db86aabSstevel #define	SOCAL_ADISC_TIMEOUT		15000000 /* usec */
197*3db86aabSstevel #define	SOCAL_RLS_TIMEOUT		15000000 /* usec */
198*3db86aabSstevel #define	SOCAL_DIAG_TIMEOUT		15000000 /* usec */
199*3db86aabSstevel 
200*3db86aabSstevel /*
201*3db86aabSstevel  * We wait for up to SOC_INITIAL_ONLINE seconds for the first
202*3db86aabSstevel  * soc to come on line. The timeout in the soc firmware is 10 seconds.
203*3db86aabSstevel  * The timeout is to let any outstanding commands drain before
204*3db86aabSstevel  * coming back on line, after going off-line.
205*3db86aabSstevel  */
206*3db86aabSstevel #define	SOC_INITIAL_ONLINE	30	/* secs for first online from soc */
207*3db86aabSstevel 
208*3db86aabSstevel /*
209*3db86aabSstevel  * SOC state structure
210*3db86aabSstevel  */
211*3db86aabSstevel 
212*3db86aabSstevel typedef struct socal_state {
213*3db86aabSstevel 	dev_info_t	*dip;
214*3db86aabSstevel 	caddr_t 	socal_eeprom;		/* pointer to soc+ eeprom */
215*3db86aabSstevel 	caddr_t 	socal_xrp;		/* pointer to soc+ xram */
216*3db86aabSstevel 	socal_reg_t	*socal_rp;		/* pointer to soc+ registers */
217*3db86aabSstevel 
218*3db86aabSstevel 	soc_cq_t	*xram_reqp;	/* addr of request descriptors */
219*3db86aabSstevel 	soc_cq_t	*xram_rspp;	/* addr of response descriptors */
220*3db86aabSstevel 
221*3db86aabSstevel 	socal_kcq_t	request[SOCAL_N_CQS];	/* request queues */
222*3db86aabSstevel 	socal_kcq_t	response[SOCAL_N_CQS];	/* response queues */
223*3db86aabSstevel 
224*3db86aabSstevel 	int32_t		socal_busy;		/* busy flag */
225*3db86aabSstevel 	uint32_t	socal_shutdown;
226*3db86aabSstevel 	uint32_t	socal_cfg;		/* copy of the config reg */
227*3db86aabSstevel 
228*3db86aabSstevel 	kmutex_t	k_imr_mtx;	/* mutex for interrupt masks */
229*3db86aabSstevel 	uint32_t	socal_k_imr;	/* copy of soc+'s mask register */
230*3db86aabSstevel 
231*3db86aabSstevel 	kmutex_t	abort_mtx;	/* Abort mutex. */
232*3db86aabSstevel 	kmutex_t	board_mtx;	/* Per board mutex */
233*3db86aabSstevel 	kmutex_t	ioctl_mtx;	/* mutex to serialize ioctls */
234*3db86aabSstevel 	kcondvar_t	board_cv;	/* Per board condition variable */
235*3db86aabSstevel 
236*3db86aabSstevel 	ddi_iblock_cookie_t	iblkc;	/* interrupt cookies */
237*3db86aabSstevel 	ddi_idevice_cookie_t	idevc;
238*3db86aabSstevel 
239*3db86aabSstevel 	uchar_t		*pool;	/* unsolicited buffer pool resources */
240*3db86aabSstevel 	ddi_dma_handle_t	pool_dhandle;
241*3db86aabSstevel 	ddi_dma_cookie_t	pool_dcookie;
242*3db86aabSstevel 	ddi_acc_handle_t	pool_acchandle;
243*3db86aabSstevel 
244*3db86aabSstevel 					/* handles to soc+ ports */
245*3db86aabSstevel 	socal_port_t	port_state[N_SOCAL_NPORTS];
246*3db86aabSstevel 	la_wwn_t	socal_n_wwn;	/* Our Node WorldWide Name */
247*3db86aabSstevel 	char		socal_service_params[SOCAL_SVC_LENGTH];	/* for login */
248*3db86aabSstevel 
249*3db86aabSstevel 	char			socal_name[MAXPATHLEN];
250*3db86aabSstevel 	kstat_t			*socal_ksp;
251*3db86aabSstevel 	struct socal_stats	socal_stats;	/* kstats */
252*3db86aabSstevel 	int		socal_on_intr;
253*3db86aabSstevel } socal_state_t;
254*3db86aabSstevel 
255*3db86aabSstevel /*
256*3db86aabSstevel  * Structure used when the soc driver needs to issue commands of its own
257*3db86aabSstevel  */
258*3db86aabSstevel 
259*3db86aabSstevel typedef struct socal_priv_cmd {
260*3db86aabSstevel 	void			*fapktp;
261*3db86aabSstevel 	uint32_t		flags;
262*3db86aabSstevel 	caddr_t			cmd;
263*3db86aabSstevel 	caddr_t			rsp;
264*3db86aabSstevel 	ddi_dma_handle_t	cmd_handle;
265*3db86aabSstevel 	ddi_acc_handle_t	cmd_acchandle;
266*3db86aabSstevel 	ddi_dma_handle_t	rsp_handle;
267*3db86aabSstevel 	ddi_acc_handle_t	rsp_acchandle;
268*3db86aabSstevel 	void 			(*callback)();	/* callback to ULP, if any */
269*3db86aabSstevel 	void			*arg;		/* callback arg */
270*3db86aabSstevel 	caddr_t			*payload;	/* payload callback or stash */
271*3db86aabSstevel } socal_priv_cmd_t;
272*3db86aabSstevel 
273*3db86aabSstevel #ifdef __cplusplus
274*3db86aabSstevel }
275*3db86aabSstevel #endif
276*3db86aabSstevel 
277*3db86aabSstevel #endif /* !_SYS_SOCALVAR_H */
278