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