1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef _CS_PRIV_H
28*7c478bd9Sstevel@tonic-gate #define	_CS_PRIV_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
31*7c478bd9Sstevel@tonic-gate extern "C" {
32*7c478bd9Sstevel@tonic-gate #endif
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate /*
35*7c478bd9Sstevel@tonic-gate  * PCMCIA Card Services private header file
36*7c478bd9Sstevel@tonic-gate  */
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate /*
39*7c478bd9Sstevel@tonic-gate  * typedef for function pointers to quiet lint and cc -v
40*7c478bd9Sstevel@tonic-gate  */
41*7c478bd9Sstevel@tonic-gate typedef	int32_t (f_t)(int32_t, ...);	/* for lint - cc -v quieting */
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate /*
44*7c478bd9Sstevel@tonic-gate  * Magic number we use when talking with Socket Services
45*7c478bd9Sstevel@tonic-gate  */
46*7c478bd9Sstevel@tonic-gate #define	CS_MAGIC	PCCS_MAGIC
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate /*
49*7c478bd9Sstevel@tonic-gate  * Make the calls to SocketServices and the CIS Parser look like
50*7c478bd9Sstevel@tonic-gate  *	function calls.
51*7c478bd9Sstevel@tonic-gate  */
52*7c478bd9Sstevel@tonic-gate #define	SocketServices	(*cs_socket_services)
53*7c478bd9Sstevel@tonic-gate #define	CIS_PARSER	(*cis_parser)
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate /*
56*7c478bd9Sstevel@tonic-gate  * CIS_DEFAULT_SPEED is the default speed to use to read the CIS
57*7c478bd9Sstevel@tonic-gate  *	in AM space.  It is expressed in nS.
58*7c478bd9Sstevel@tonic-gate  */
59*7c478bd9Sstevel@tonic-gate #define	CIS_DEFAULT_SPEED	250
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate /*
62*7c478bd9Sstevel@tonic-gate  * This is the IO window speed.
63*7c478bd9Sstevel@tonic-gate  */
64*7c478bd9Sstevel@tonic-gate #define	IO_WIN_SPEED		250
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate /*
67*7c478bd9Sstevel@tonic-gate  * Flags to support various internal first/next functions. All of
68*7c478bd9Sstevel@tonic-gate  *	these must be within CIS_GET_LTUPLE_OPMASK which is defined
69*7c478bd9Sstevel@tonic-gate  *	in the cis.h file. Values outside this mask range are used
70*7c478bd9Sstevel@tonic-gate  *	internally by the CIS parser.
71*7c478bd9Sstevel@tonic-gate  */
72*7c478bd9Sstevel@tonic-gate #define	CS_GET_FIRST_FLAG	0x0001
73*7c478bd9Sstevel@tonic-gate #define	CS_GET_NEXT_FLAG	0x0002
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate /*
76*7c478bd9Sstevel@tonic-gate  * Macros to manipulate bits - only does up to uint32_t size
77*7c478bd9Sstevel@tonic-gate  */
78*7c478bd9Sstevel@tonic-gate #define	CS_BIT_WORDSIZE		(sizeof (uint32_t))
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate #define	CS_BIT_GET(val, bit)	\
81*7c478bd9Sstevel@tonic-gate 			((uint32_t)(val) & (uint32_t)(1<<(uint32_t)(bit)))
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate #define	CS_BIT_CLEAR(val, bit)	((val) &= (uint32_t)~(1<<(uint32_t)(bit)))
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate #define	CS_BIT_SET(val, bit)	\
86*7c478bd9Sstevel@tonic-gate 			((uint32_t)(val) |= (uint32_t)(1<<(uint32_t)(bit)))
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate /*
89*7c478bd9Sstevel@tonic-gate  * Minimum time to wait after socket reset before we are allowed to
90*7c478bd9Sstevel@tonic-gate  *	access the card.  The PCMCIA specification says at least 20mS
91*7c478bd9Sstevel@tonic-gate  *	must elapse from the time that the card is reset until the
92*7c478bd9Sstevel@tonic-gate  *	first access of any kind can be made to the card. This time
93*7c478bd9Sstevel@tonic-gate  *	value is expressed in mS.
94*7c478bd9Sstevel@tonic-gate  */
95*7c478bd9Sstevel@tonic-gate #define	RESET_TIMEOUT_TIME	180
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate /*
98*7c478bd9Sstevel@tonic-gate  * Maximum time to wait for card ready after resetting the socket.
99*7c478bd9Sstevel@tonic-gate  *	We wait for card ready a maximum of 20 seconds after card
100*7c478bd9Sstevel@tonic-gate  *	reset before considering that we have an error condition.
101*7c478bd9Sstevel@tonic-gate  * XXX - what does PCMCIA specify as the max time here??
102*7c478bd9Sstevel@tonic-gate  */
103*7c478bd9Sstevel@tonic-gate #define	READY_TIMEOUT_TIME	(drv_usectohz(20000000))
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate /*
106*7c478bd9Sstevel@tonic-gate  * Time between periodically kicking the soft interrupt handler.
107*7c478bd9Sstevel@tonic-gate  */
108*7c478bd9Sstevel@tonic-gate #define	SOFTINT_TIMEOUT_TIME	(drv_usectohz(2000000))
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate /*
111*7c478bd9Sstevel@tonic-gate  * Various delays are necessary when switching the card and socket
112*7c478bd9Sstevel@tonic-gate  *	between IO and memory modes. All delays are in mS.
113*7c478bd9Sstevel@tonic-gate  *
114*7c478bd9Sstevel@tonic-gate  *  cs_request_configuration parameters:
115*7c478bd9Sstevel@tonic-gate  *    CS_RC1_DELAY - delay between writing COR and switching socket
116*7c478bd9Sstevel@tonic-gate  *			to IO mode
117*7c478bd9Sstevel@tonic-gate  *    CS_RC2_DELAY - delay after switching socket to IO mode
118*7c478bd9Sstevel@tonic-gate  *
119*7c478bd9Sstevel@tonic-gate  *  cs_release_configuration parameters:
120*7c478bd9Sstevel@tonic-gate  *	CS_RQ_DELAY - amount of time that the RESET bit in the COR is
121*7c478bd9Sstevel@tonic-gate  *			held asserted
122*7c478bd9Sstevel@tonic-gate  */
123*7c478bd9Sstevel@tonic-gate #define	CS_RC1_DELAY		20	/* COR->IO delay in mS */
124*7c478bd9Sstevel@tonic-gate #define	CS_RC2_DELAY		300	/* post-COR delay in mS */
125*7c478bd9Sstevel@tonic-gate #define	CS_RQ_DELAY		100	/* COR(RESET) delay in mS */
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate /*
128*7c478bd9Sstevel@tonic-gate  * Handy macro to do untimeout.
129*7c478bd9Sstevel@tonic-gate  */
130*7c478bd9Sstevel@tonic-gate #define	UNTIMEOUT(id)		\
131*7c478bd9Sstevel@tonic-gate 	if ((id)) {		\
132*7c478bd9Sstevel@tonic-gate 	    (void) untimeout((id));	\
133*7c478bd9Sstevel@tonic-gate 	    (id) = 0;		\
134*7c478bd9Sstevel@tonic-gate 	}
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate /*
137*7c478bd9Sstevel@tonic-gate  * Macros to enter/exit event thread mutex
138*7c478bd9Sstevel@tonic-gate  */
139*7c478bd9Sstevel@tonic-gate #define	EVENT_THREAD_MUTEX_ENTER(acq, sp)		\
140*7c478bd9Sstevel@tonic-gate 	acq = !MUTEX_HELD(&sp->client_lock);		\
141*7c478bd9Sstevel@tonic-gate 	if (acq)					\
142*7c478bd9Sstevel@tonic-gate 	    mutex_enter(&sp->client_lock);
143*7c478bd9Sstevel@tonic-gate #define	EVENT_THREAD_MUTEX_EXIT(acq, sp)		\
144*7c478bd9Sstevel@tonic-gate 	if (acq)					\
145*7c478bd9Sstevel@tonic-gate 	    mutex_exit(&sp->client_lock);
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate /*
148*7c478bd9Sstevel@tonic-gate  * cisregister_t structure is used to support the CISRegister
149*7c478bd9Sstevel@tonic-gate  *	and the CISUnregister function calls
150*7c478bd9Sstevel@tonic-gate  */
151*7c478bd9Sstevel@tonic-gate typedef struct cisregister_t {
152*7c478bd9Sstevel@tonic-gate 	uint32_t		cis_magic;
153*7c478bd9Sstevel@tonic-gate 	uint32_t		cis_version;
154*7c478bd9Sstevel@tonic-gate 	void *			(*cis_parser)(int32_t function, ...);
155*7c478bd9Sstevel@tonic-gate 	cistpl_callout_t	*cistpl_std_callout; /* standard callout list */
156*7c478bd9Sstevel@tonic-gate } cisregister_t;
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate /*
159*7c478bd9Sstevel@tonic-gate  * These two defines are to support CISRegister and CISUnregister
160*7c478bd9Sstevel@tonic-gate  */
161*7c478bd9Sstevel@tonic-gate #define	CIS_MAGIC	0x20434953
162*7c478bd9Sstevel@tonic-gate #define	CIS_VERSION	_VERSION(0, 1)
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate /*
165*7c478bd9Sstevel@tonic-gate  * CS_MAX_CIS defines the number of CIS chains that we hang off the per-socket
166*7c478bd9Sstevel@tonic-gate  *	structure.
167*7c478bd9Sstevel@tonic-gate  *
168*7c478bd9Sstevel@tonic-gate  * CS_GLOBAL_CIS defines the index where the CIS parser puts the first CIS list
169*7c478bd9Sstevel@tonic-gate  *	for a single-function card or the global CIS list for a multi-function
170*7c478bd9Sstevel@tonic-gate  *	card.
171*7c478bd9Sstevel@tonic-gate  *
172*7c478bd9Sstevel@tonic-gate  * CS_MAX_CIS is one greater than CIS_MAX_FUNCTIONS since the CIS parser
173*7c478bd9Sstevel@tonic-gate  *	puts the global CIS chain on the CS_GLOBAL_CIS function index as
174*7c478bd9Sstevel@tonic-gate  * 	follows:
175*7c478bd9Sstevel@tonic-gate  *
176*7c478bd9Sstevel@tonic-gate  *	For single-function cards:
177*7c478bd9Sstevel@tonic-gate  *	    sp->cis[0] - CIS chain
178*7c478bd9Sstevel@tonic-gate  *	    sp->cis[1..(CIS_MAX_FUNCTIONS - 1)] - not used
179*7c478bd9Sstevel@tonic-gate  *	    sp->cis[CS_GLOBAL_CIS] - not used
180*7c478bd9Sstevel@tonic-gate  *
181*7c478bd9Sstevel@tonic-gate  *	For multi-function cards:
182*7c478bd9Sstevel@tonic-gate  *	    sp->cis[0..(CIS_MAX_FUNCTIONS - 1)] - global CIS chain followed
183*7c478bd9Sstevel@tonic-gate  *					by per-function CIS chain
184*7c478bd9Sstevel@tonic-gate  *	    sp->cis[CS_GLOBAL_CIS] - global CIS chain
185*7c478bd9Sstevel@tonic-gate  */
186*7c478bd9Sstevel@tonic-gate #define	CS_MAX_CIS	(CIS_MAX_FUNCTIONS + 1)
187*7c478bd9Sstevel@tonic-gate #define	CS_GLOBAL_CIS	CIS_MAX_FUNCTIONS
188*7c478bd9Sstevel@tonic-gate 
189*7c478bd9Sstevel@tonic-gate /*
190*7c478bd9Sstevel@tonic-gate  * CS_SS_CLIENT_HANDLE is a special client handle that Socket Services gets
191*7c478bd9Sstevel@tonic-gate  *	when it registers with RegisterClient.
192*7c478bd9Sstevel@tonic-gate  */
193*7c478bd9Sstevel@tonic-gate #define	CS_SS_CLIENT_HANDLE	0x00000000
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate /*
196*7c478bd9Sstevel@tonic-gate  * Client handle, socket number, function number and socket pointer
197*7c478bd9Sstevel@tonic-gate  *	macros. The client handle encoding is private to Card Services,
198*7c478bd9Sstevel@tonic-gate  *	and external modules should not use these macros to manipulate
199*7c478bd9Sstevel@tonic-gate  *	client handles.
200*7c478bd9Sstevel@tonic-gate  *
201*7c478bd9Sstevel@tonic-gate  *	The encoding of the client handle is:
202*7c478bd9Sstevel@tonic-gate  *
203*7c478bd9Sstevel@tonic-gate  *		xxxxxfff | xsssssss | cccccccc | cccccccc
204*7c478bd9Sstevel@tonic-gate  *
205*7c478bd9Sstevel@tonic-gate  *	f - function number bit
206*7c478bd9Sstevel@tonic-gate  *	s - socket number bit
207*7c478bd9Sstevel@tonic-gate  *	c - client number bit
208*7c478bd9Sstevel@tonic-gate  *	x - don't care bits
209*7c478bd9Sstevel@tonic-gate  */
210*7c478bd9Sstevel@tonic-gate #define	CLIENT_HANDLE_IS_SS(ch)		(!GET_CLIENT_MINOR((ch)))
211*7c478bd9Sstevel@tonic-gate #define	CS_MAX_SOCKETS_MASK		(PCMCIA_MAX_SOCKETS - 1)
212*7c478bd9Sstevel@tonic-gate #define	CS_MAX_FUNCTIONS_MASK		(CIS_MAX_FUNCTIONS - 1)
213*7c478bd9Sstevel@tonic-gate #define	CS_MAX_CLIENTS_MASK		0x0ffff
214*7c478bd9Sstevel@tonic-gate #define	CS_MAX_CLIENTS			(CS_MAX_CLIENTS_MASK - 2)
215*7c478bd9Sstevel@tonic-gate #define	MAKE_CLIENT_HANDLE(s, f, c)	((((f)&CS_MAX_FUNCTIONS_MASK)<<24) | \
216*7c478bd9Sstevel@tonic-gate 					    (((s)&CS_MAX_SOCKETS_MASK)<<16) | \
217*7c478bd9Sstevel@tonic-gate 					    ((c)&CS_MAX_CLIENTS_MASK))
218*7c478bd9Sstevel@tonic-gate #define	GET_CLIENT_SOCKET(ch)		(((ch)>>16)&CS_MAX_SOCKETS_MASK)
219*7c478bd9Sstevel@tonic-gate #define	GET_CLIENT_FUNCTION(ch)		(((ch)>>24)&CS_MAX_FUNCTIONS_MASK)
220*7c478bd9Sstevel@tonic-gate #define	GET_CLIENT_MINOR(ch)		((ch)&CS_MAX_CLIENTS_MASK)
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate /*
223*7c478bd9Sstevel@tonic-gate  * Socket number macros. These are used by Socket Services, CSI
224*7c478bd9Sstevel@tonic-gate  *	drivers and the "super-client" driver to specify which
225*7c478bd9Sstevel@tonic-gate  *	socket and function number on that socket they wish to
226*7c478bd9Sstevel@tonic-gate  *	manipulate. This socket number encoding is typically passed
227*7c478bd9Sstevel@tonic-gate  *	to various Card Services functions by these drivers.
228*7c478bd9Sstevel@tonic-gate  *
229*7c478bd9Sstevel@tonic-gate  *	The encoding of the socket number is:
230*7c478bd9Sstevel@tonic-gate  *
231*7c478bd9Sstevel@tonic-gate  *		xxxxxxxx | xxxxgfff | xxxxxxxx | xsssssss
232*7c478bd9Sstevel@tonic-gate  *
233*7c478bd9Sstevel@tonic-gate  *	g - global CIS bit
234*7c478bd9Sstevel@tonic-gate  *	f - function number bit
235*7c478bd9Sstevel@tonic-gate  *	s - socket number bit
236*7c478bd9Sstevel@tonic-gate  *	x - don't care bits
237*7c478bd9Sstevel@tonic-gate  */
238*7c478bd9Sstevel@tonic-gate #define	CS_GET_SOCKET_NUMBER(s)		((s)&CS_MAX_SOCKETS_MASK)
239*7c478bd9Sstevel@tonic-gate #define	CS_GET_FUNCTION_NUMBER(s)	(((s)>>16)&(CS_MAX_FUNCTIONS_MASK | \
240*7c478bd9Sstevel@tonic-gate 							CIS_MAX_FUNCTIONS))
241*7c478bd9Sstevel@tonic-gate #define	CS_SET_SOCKET_NUMBER(s)		((s)&CS_MAX_SOCKETS_MASK)
242*7c478bd9Sstevel@tonic-gate #define	CS_SET_FUNCTION_NUMBER(f)	(((f)&(CS_MAX_FUNCTIONS_MASK | \
243*7c478bd9Sstevel@tonic-gate 						CIS_MAX_FUNCTIONS))<<16)
244*7c478bd9Sstevel@tonic-gate #define	CS_MAKE_SOCKET_NUMBER(s, f)	(CS_SET_SOCKET_NUMBER(s) | \
245*7c478bd9Sstevel@tonic-gate 						CS_SET_FUNCTION_NUMBER(f))
246*7c478bd9Sstevel@tonic-gate 
247*7c478bd9Sstevel@tonic-gate /*
248*7c478bd9Sstevel@tonic-gate  * DIP2SOCKET_NUM(dip) - this macro gets the PCM_DEV_SOCKET property from
249*7c478bd9Sstevel@tonic-gate  *	the passed dip.  If the property can't be found, then the default
250*7c478bd9Sstevel@tonic-gate  *	value of cs_globals.max_socket_num is returned.
251*7c478bd9Sstevel@tonic-gate  */
252*7c478bd9Sstevel@tonic-gate #define	DIP2SOCKET_NUM(dip)		ddi_getprop(DDI_DEV_T_NONE, dip,\
253*7c478bd9Sstevel@tonic-gate 						(DDI_PROP_CANSLEEP |	\
254*7c478bd9Sstevel@tonic-gate 							DDI_PROP_NOTPROM), \
255*7c478bd9Sstevel@tonic-gate 						PCM_DEV_SOCKET,		\
256*7c478bd9Sstevel@tonic-gate 						cs_globals.max_socket_num)
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate /*
259*7c478bd9Sstevel@tonic-gate  * Range checking macros
260*7c478bd9Sstevel@tonic-gate  *
261*7c478bd9Sstevel@tonic-gate  * CHECK_SOCKET_NUM(socket_number, max_sockets) returns 1 if
262*7c478bd9Sstevel@tonic-gate  *	socket_number is in range
263*7c478bd9Sstevel@tonic-gate  */
264*7c478bd9Sstevel@tonic-gate #define	CHECK_SOCKET_NUM(sn, ms)	(((sn) >= (ms))?0:1)
265*7c478bd9Sstevel@tonic-gate 
266*7c478bd9Sstevel@tonic-gate /*
267*7c478bd9Sstevel@tonic-gate  * window macros
268*7c478bd9Sstevel@tonic-gate  *
269*7c478bd9Sstevel@tonic-gate  * These all expect that the window has been validated as a valid
270*7c478bd9Sstevel@tonic-gate  *	window (i.e. CW_WINDOW_VALID is set in window state)
271*7c478bd9Sstevel@tonic-gate  *
272*7c478bd9Sstevel@tonic-gate  * Note that WINDOW_FOR_SOCKET expects a socket mask for the wsm
273*7c478bd9Sstevel@tonic-gate  *	parameter (this is a socket_enum_t type, and NOT just a
274*7c478bd9Sstevel@tonic-gate  *	plain old uint32_t)
275*7c478bd9Sstevel@tonic-gate  */
276*7c478bd9Sstevel@tonic-gate #define	WINDOW_FOR_SOCKET(wsm, sn)	((wsm)[sn/PR_WORDSIZE] & \
277*7c478bd9Sstevel@tonic-gate 						(1 << ((sn) & PR_MASK)))
278*7c478bd9Sstevel@tonic-gate #define	WINDOW_AVAILABLE_FOR_MEM(cwp)	(!(cwp->state & CW_WIN_IN_USE))
279*7c478bd9Sstevel@tonic-gate #define	WINDOW_AVAILABLE_FOR_IO(cwp)	\
280*7c478bd9Sstevel@tonic-gate 		(!(cwp->state & (CW_CIS | CW_MEM | CW_ALLOCATED)))
281*7c478bd9Sstevel@tonic-gate 
282*7c478bd9Sstevel@tonic-gate /*
283*7c478bd9Sstevel@tonic-gate  * IO Base and NumPorts address frobnitz macros
284*7c478bd9Sstevel@tonic-gate  */
285*7c478bd9Sstevel@tonic-gate #define	IOADDR_FROBNITZ(Base, IOAddrLines)	(Base&((1<<IOAddrLines)-1))
286*7c478bd9Sstevel@tonic-gate #define	IONUMPORTS_FROBNITZ(np)			(((np)&1)?((np)+1):(np))
287*7c478bd9Sstevel@tonic-gate 
288*7c478bd9Sstevel@tonic-gate /*
289*7c478bd9Sstevel@tonic-gate  * Structure that contains offsets to the card's configuration registers
290*7c478bd9Sstevel@tonic-gate  *	as well as copies of the data written to them in RequestConfiguration.
291*7c478bd9Sstevel@tonic-gate  *	We use an offset per register approach since not all cards have
292*7c478bd9Sstevel@tonic-gate  *	all registers implemented, and by specifying a NULL register offset,
293*7c478bd9Sstevel@tonic-gate  *	we know not to try to access that register.
294*7c478bd9Sstevel@tonic-gate  */
295*7c478bd9Sstevel@tonic-gate typedef struct config_regs_t {
296*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	cor;		/* Configuration Option Register */
297*7c478bd9Sstevel@tonic-gate 	uint32_t	cor_p;
298*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	ccsr;		/* Configuration and Status Register */
299*7c478bd9Sstevel@tonic-gate 	uint32_t	ccsr_p;
300*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	prr;		/* Pin Replacement Register */
301*7c478bd9Sstevel@tonic-gate 	uint32_t	prr_p;
302*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	scr;		/* Socket and Copy Register */
303*7c478bd9Sstevel@tonic-gate 	uint32_t	scr_p;
304*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	exstat;		/* Extended Status Register */
305*7c478bd9Sstevel@tonic-gate 	uint32_t	exstat_p;
306*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	iobase0;	/* IO Base 0 Register */
307*7c478bd9Sstevel@tonic-gate 	uint32_t	iobase0_p;
308*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	iobase1;	/* IO Base 1 Register */
309*7c478bd9Sstevel@tonic-gate 	uint32_t	iobase1_p;
310*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	iobase2;	/* IO Base 2 Register */
311*7c478bd9Sstevel@tonic-gate 	uint32_t	iobase2_p;
312*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	iobase3;	/* IO Base 3 Register */
313*7c478bd9Sstevel@tonic-gate 	uint32_t	iobase3_p;
314*7c478bd9Sstevel@tonic-gate 	cfg_regs_t	iolimit;	/* IO Limit Register */
315*7c478bd9Sstevel@tonic-gate 	uint32_t	iolimit_p;
316*7c478bd9Sstevel@tonic-gate } config_regs_t;
317*7c478bd9Sstevel@tonic-gate 
318*7c478bd9Sstevel@tonic-gate /*
319*7c478bd9Sstevel@tonic-gate  * Macro to make calling the client's event handler look like a function.
320*7c478bd9Sstevel@tonic-gate  */
321*7c478bd9Sstevel@tonic-gate #define	CLIENT_EVENT_CALLBACK(cp, event, pri)		\
322*7c478bd9Sstevel@tonic-gate 	    (cp)->event_callback_handler(event, pri,	\
323*7c478bd9Sstevel@tonic-gate 			&(cp)->event_callback_args)
324*7c478bd9Sstevel@tonic-gate 
325*7c478bd9Sstevel@tonic-gate /*
326*7c478bd9Sstevel@tonic-gate  * Macro to return event in PRR - this also clears the changed bit if
327*7c478bd9Sstevel@tonic-gate  *	the event occured.
328*7c478bd9Sstevel@tonic-gate  */
329*7c478bd9Sstevel@tonic-gate #define	PRR_EVENT(prrx, pe, ps, ce, re)	\
330*7c478bd9Sstevel@tonic-gate 	if (prrx & pe) {		\
331*7c478bd9Sstevel@tonic-gate 	    if (prrx & ps)		\
332*7c478bd9Sstevel@tonic-gate 		(re) |= ce;		\
333*7c478bd9Sstevel@tonic-gate 	    prrx &= ~pe;		\
334*7c478bd9Sstevel@tonic-gate 	    prrx |= ps;			\
335*7c478bd9Sstevel@tonic-gate 	}
336*7c478bd9Sstevel@tonic-gate 
337*7c478bd9Sstevel@tonic-gate /*
338*7c478bd9Sstevel@tonic-gate  * io_alloc_t struct used to keep track of a client's IO window allocation
339*7c478bd9Sstevel@tonic-gate  */
340*7c478bd9Sstevel@tonic-gate typedef struct io_alloc_t {
341*7c478bd9Sstevel@tonic-gate 	uint32_t	Window1;	/* allocated IO window no. for set #1 */
342*7c478bd9Sstevel@tonic-gate 	baseaddru_t	BasePort1;	/* 1st IO range base address or port */
343*7c478bd9Sstevel@tonic-gate 	uint32_t	NumPorts1;	/* 1st IO range no. contiguous ports */
344*7c478bd9Sstevel@tonic-gate 	uint32_t	Attributes1;	/* 1st IO range attributes */
345*7c478bd9Sstevel@tonic-gate 	uint32_t	Window2;	/* allocated IO window no. for set #2 */
346*7c478bd9Sstevel@tonic-gate 	baseaddru_t	BasePort2;	/* s2nd IO range base address or port */
347*7c478bd9Sstevel@tonic-gate 	uint32_t	NumPorts2;	/* 2nd IO range no. contiguous ports */
348*7c478bd9Sstevel@tonic-gate 	uint32_t	Attributes2;	/* second IO range attributes */
349*7c478bd9Sstevel@tonic-gate 	uint32_t	IOAddrLines;	/* number of IO address lines decoded */
350*7c478bd9Sstevel@tonic-gate } io_alloc_t;
351*7c478bd9Sstevel@tonic-gate 
352*7c478bd9Sstevel@tonic-gate /*
353*7c478bd9Sstevel@tonic-gate  * irq_alloc_t structure used to keep track of a client's IRQ allocation
354*7c478bd9Sstevel@tonic-gate  */
355*7c478bd9Sstevel@tonic-gate typedef struct irq_alloc_t {
356*7c478bd9Sstevel@tonic-gate 	uint32_t	Attributes;	/* IRQ attribute flags */
357*7c478bd9Sstevel@tonic-gate 	uint32_t	irq;		/* assigned IRQ number */
358*7c478bd9Sstevel@tonic-gate 	uint32_t	handler_id;	/* IRQ handler ID for this IRQ */
359*7c478bd9Sstevel@tonic-gate 	f_t		*irq_handler;
360*7c478bd9Sstevel@tonic-gate 	void		*irq_handler_arg1;
361*7c478bd9Sstevel@tonic-gate 	void		*irq_handler_arg2;
362*7c478bd9Sstevel@tonic-gate } irq_alloc_t;
363*7c478bd9Sstevel@tonic-gate 
364*7c478bd9Sstevel@tonic-gate /*
365*7c478bd9Sstevel@tonic-gate  * The client data structure
366*7c478bd9Sstevel@tonic-gate  */
367*7c478bd9Sstevel@tonic-gate typedef struct client_t {
368*7c478bd9Sstevel@tonic-gate 	client_handle_t	client_handle;	/* this client's client handle */
369*7c478bd9Sstevel@tonic-gate 	unsigned	flags;		/* client flags */
370*7c478bd9Sstevel@tonic-gate 	/* resource control */
371*7c478bd9Sstevel@tonic-gate 	uint32_t	memwin_count;	/* number of mem windows allocated */
372*7c478bd9Sstevel@tonic-gate 	io_alloc_t	io_alloc;	/* IO resource allocations */
373*7c478bd9Sstevel@tonic-gate 	irq_alloc_t	irq_alloc;	/* IRQ resource allocations */
374*7c478bd9Sstevel@tonic-gate 	/* event support */
375*7c478bd9Sstevel@tonic-gate 	uint32_t	event_mask;	/* client event mask */
376*7c478bd9Sstevel@tonic-gate 	uint32_t	global_mask;	/* client global event mask */
377*7c478bd9Sstevel@tonic-gate 	uint32_t	events;		/* current events pending */
378*7c478bd9Sstevel@tonic-gate 	uint32_t	pending_events;	/* events pending in RegisterClient */
379*7c478bd9Sstevel@tonic-gate 	csfunction_t	*event_callback_handler;
380*7c478bd9Sstevel@tonic-gate 	event_callback_args_t	event_callback_args;
381*7c478bd9Sstevel@tonic-gate 	/* config registers support */
382*7c478bd9Sstevel@tonic-gate 	config_regs_t	config_regs;	/* pointers to config registers */
383*7c478bd9Sstevel@tonic-gate 	uint32_t	config_regs_offset; /* offset from start of AM */
384*7c478bd9Sstevel@tonic-gate 	unsigned	pin;		/* valid bits in PRR */
385*7c478bd9Sstevel@tonic-gate 	uint32_t	present;	/* which config registers present */
386*7c478bd9Sstevel@tonic-gate 	/* DDI support */
387*7c478bd9Sstevel@tonic-gate 	dev_info_t	*dip;		/* this client's dip */
388*7c478bd9Sstevel@tonic-gate 	char		*driver_name;	/* client's driver name */
389*7c478bd9Sstevel@tonic-gate 	int32_t		instance;	/* client's driver instance */
390*7c478bd9Sstevel@tonic-gate 	/* list control */
391*7c478bd9Sstevel@tonic-gate 	struct client_t	*next;		/* next client pointer */
392*7c478bd9Sstevel@tonic-gate 	struct client_t	*prev;		/* previous client pointer */
393*7c478bd9Sstevel@tonic-gate } client_t;
394*7c478bd9Sstevel@tonic-gate 
395*7c478bd9Sstevel@tonic-gate /*
396*7c478bd9Sstevel@tonic-gate  * Flags for client structure - note that we share the client_t->flags
397*7c478bd9Sstevel@tonic-gate  *	member with the definitions in cs.h that are used by the
398*7c478bd9Sstevel@tonic-gate  *	RegisterClient function.
399*7c478bd9Sstevel@tonic-gate  *
400*7c478bd9Sstevel@tonic-gate  * We can start our flags from 0x00001000 and on up.
401*7c478bd9Sstevel@tonic-gate  */
402*7c478bd9Sstevel@tonic-gate #define	REQ_CONFIGURATION_DONE	0x00001000	/* RequestConfiguration done */
403*7c478bd9Sstevel@tonic-gate #define	REQ_SOCKET_MASK_DONE	0x00002000	/* RequestSocketMask done */
404*7c478bd9Sstevel@tonic-gate #define	REQ_IO_DONE		0x00004000	/* RequestIO done */
405*7c478bd9Sstevel@tonic-gate #define	REQ_IRQ_DONE		0x00008000	/* RequestIRQ done */
406*7c478bd9Sstevel@tonic-gate #define	CLIENT_SUPER_CLIENT	0x00010000	/* "super-client" client */
407*7c478bd9Sstevel@tonic-gate #define	CLIENT_CSI_CLIENT	0x00020000	/* CSI client */
408*7c478bd9Sstevel@tonic-gate #define	CLIENT_CARD_INSERTED	0x00100000	/* current card for client */
409*7c478bd9Sstevel@tonic-gate #define	CLIENT_SENT_INSERTION	0x00200000	/* send CARD_INSERTION */
410*7c478bd9Sstevel@tonic-gate #define	CLIENT_MTD_IN_PROGRESS	0x01000000	/* MTD op in progress */
411*7c478bd9Sstevel@tonic-gate #define	CLIENT_IO_ALLOCATED	0x02000000	/* IO resources allocated */
412*7c478bd9Sstevel@tonic-gate #define	CLIENT_IRQ_ALLOCATED	0x04000000	/* IRQ resources allocated */
413*7c478bd9Sstevel@tonic-gate #define	CLIENT_WIN_ALLOCATED	0x08000000	/* window resources allocated */
414*7c478bd9Sstevel@tonic-gate 
415*7c478bd9Sstevel@tonic-gate #ifdef	USE_IOMMAP_WINDOW
416*7c478bd9Sstevel@tonic-gate /*
417*7c478bd9Sstevel@tonic-gate  * io_mmap_window_t structure that describes the memory-mapped IO
418*7c478bd9Sstevel@tonic-gate  *	window on this socket
419*7c478bd9Sstevel@tonic-gate  */
420*7c478bd9Sstevel@tonic-gate typedef struct io_mmap_window_t {
421*7c478bd9Sstevel@tonic-gate 	uint32_t		flags;	/* window flags */
422*7c478bd9Sstevel@tonic-gate 	uint32_t		number;	/* IO window number */
423*7c478bd9Sstevel@tonic-gate 	uint32_t		size;	/* size of mapped IO window */
424*7c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t	handle;	/* window mapped base address */
425*7c478bd9Sstevel@tonic-gate 	uint32_t		count;	/* referance count */
426*7c478bd9Sstevel@tonic-gate } io_mmap_window_t;
427*7c478bd9Sstevel@tonic-gate #endif	/* USE_IOMMAP_WINDOW */
428*7c478bd9Sstevel@tonic-gate 
429*7c478bd9Sstevel@tonic-gate /*
430*7c478bd9Sstevel@tonic-gate  * cis_info_t structure used to hold per-socket CIS information
431*7c478bd9Sstevel@tonic-gate  */
432*7c478bd9Sstevel@tonic-gate typedef struct cis_info_t {
433*7c478bd9Sstevel@tonic-gate 	uint32_t	flags;		/* CIS-specific flags */
434*7c478bd9Sstevel@tonic-gate 	cistpl_t	*cis;		/* CIS linked lists */
435*7c478bd9Sstevel@tonic-gate 	uint32_t	nchains;	/* number of tuple chains in CIS */
436*7c478bd9Sstevel@tonic-gate 	uint32_t	ntuples;	/* number of tuples in CIS */
437*7c478bd9Sstevel@tonic-gate } cis_info_t;
438*7c478bd9Sstevel@tonic-gate 
439*7c478bd9Sstevel@tonic-gate /*
440*7c478bd9Sstevel@tonic-gate  * cs_adapter_t structure used to hold per-socket
441*7c478bd9Sstevel@tonic-gate  *	adapter-specific info
442*7c478bd9Sstevel@tonic-gate  */
443*7c478bd9Sstevel@tonic-gate typedef struct cs_adapter_t {
444*7c478bd9Sstevel@tonic-gate 	uint32_t	flags;		/* adapter flags */
445*7c478bd9Sstevel@tonic-gate 	char		name[MODMAXNAMELEN]; /* adapter module name */
446*7c478bd9Sstevel@tonic-gate 	uint32_t	major;		/* adapter major number */
447*7c478bd9Sstevel@tonic-gate 	uint32_t	minor;		/* adapter minor number */
448*7c478bd9Sstevel@tonic-gate 	uint32_t	instance;	/* instance number of this adapter */
449*7c478bd9Sstevel@tonic-gate 	uint32_t	number;		/* canonical adapter number */
450*7c478bd9Sstevel@tonic-gate 	uint32_t	num_sockets;	/* # sockets on this adapter */
451*7c478bd9Sstevel@tonic-gate 	uint32_t	first_socket;	/* first socket # on this adapter */
452*7c478bd9Sstevel@tonic-gate } cs_adapter_t;
453*7c478bd9Sstevel@tonic-gate 
454*7c478bd9Sstevel@tonic-gate /*
455*7c478bd9Sstevel@tonic-gate  * The per-socket structure.
456*7c478bd9Sstevel@tonic-gate  */
457*7c478bd9Sstevel@tonic-gate typedef struct cs_socket_t {
458*7c478bd9Sstevel@tonic-gate 	unsigned	socket_num;	/* socket number */
459*7c478bd9Sstevel@tonic-gate 	uint32_t	flags;		/* socket flags */
460*7c478bd9Sstevel@tonic-gate 	uint32_t	init_state;	/* cs_init state */
461*7c478bd9Sstevel@tonic-gate 	cs_adapter_t	adapter;	/* adapter info */
462*7c478bd9Sstevel@tonic-gate 	/* socket thread control and status */
463*7c478bd9Sstevel@tonic-gate 	kthread_t	*event_thread;	/* per-socket work thread */
464*7c478bd9Sstevel@tonic-gate 	uint32_t	thread_state;	/* socket thread state flags */
465*7c478bd9Sstevel@tonic-gate 	kmutex_t	lock;		/* protects events and clients */
466*7c478bd9Sstevel@tonic-gate 	kcondvar_t	thread_cv;	/* event handling synchronization */
467*7c478bd9Sstevel@tonic-gate 	kcondvar_t	caller_cv;	/* event handling synchronization */
468*7c478bd9Sstevel@tonic-gate 	kcondvar_t	reset_cv;	/* for use after card RESET */
469*7c478bd9Sstevel@tonic-gate 	uint32_t	events;		/* socket events */
470*7c478bd9Sstevel@tonic-gate 	uint32_t	event_mask;	/* socket event mask */
471*7c478bd9Sstevel@tonic-gate 	ddi_softintr_t	softint_id;	/* soft interrupt handler ID */
472*7c478bd9Sstevel@tonic-gate 	timeout_id_t	rdybsy_tmo_id;	/* timer ID for READY/BUSY timer */
473*7c478bd9Sstevel@tonic-gate 	ddi_iblock_cookie_t	*iblk;	/* event iblk cookie */
474*7c478bd9Sstevel@tonic-gate 	ddi_idevice_cookie_t	*idev;	/* event idev cookie */
475*7c478bd9Sstevel@tonic-gate 	callb_cpr_t	cprinfo_cs;	/* CPR cookie for cs_event_thread */
476*7c478bd9Sstevel@tonic-gate 	callb_cpr_t	cprinfo_ss;	/* CPR cookie for cs_ss_thread */
477*7c478bd9Sstevel@tonic-gate 	/* client management */
478*7c478bd9Sstevel@tonic-gate 	client_t	*client_list;	/* clients on this socket */
479*7c478bd9Sstevel@tonic-gate 	unsigned	next_cl_minor;	/* next available client minor num */
480*7c478bd9Sstevel@tonic-gate 	kmutex_t	client_lock;	/* protects client list */
481*7c478bd9Sstevel@tonic-gate 	uint32_t	num_clients;	/* number of clients on this socket */
482*7c478bd9Sstevel@tonic-gate 	/* CIS support */
483*7c478bd9Sstevel@tonic-gate 	uint32_t	cis_win_num;	/* CIS window number */
484*7c478bd9Sstevel@tonic-gate 	unsigned	cis_win_size;	/* CIS window size */
485*7c478bd9Sstevel@tonic-gate 	uint32_t	cis_flags;
486*7c478bd9Sstevel@tonic-gate 	uint32_t	nfuncs;		/* number of functions */
487*7c478bd9Sstevel@tonic-gate 	cis_info_t	cis[CS_MAX_CIS]; /* CIS information */
488*7c478bd9Sstevel@tonic-gate 	kmutex_t	cis_lock;	/* protects CIS */
489*7c478bd9Sstevel@tonic-gate #ifdef	USE_IOMMAP_WINDOW
490*7c478bd9Sstevel@tonic-gate 	/* memory mapped IO window support */
491*7c478bd9Sstevel@tonic-gate 	io_mmap_window_t *io_mmap_window;
492*7c478bd9Sstevel@tonic-gate #endif	/* USE_IOMMAP_WINDOW */
493*7c478bd9Sstevel@tonic-gate 	/* Socket Services work thread control and status */
494*7c478bd9Sstevel@tonic-gate 	kthread_t	*ss_thread;	/* SS work thread */
495*7c478bd9Sstevel@tonic-gate 	uint32_t	ss_thread_state; /* SS work thread state */
496*7c478bd9Sstevel@tonic-gate 	kcondvar_t	ss_thread_cv;	/* SS work thread synchronization */
497*7c478bd9Sstevel@tonic-gate 	kcondvar_t	ss_caller_cv;	/* SS work thread synchronization */
498*7c478bd9Sstevel@tonic-gate 	kmutex_t	ss_thread_lock;	/* protects SS work thread state */
499*7c478bd9Sstevel@tonic-gate 	struct cs_socket_t	*next;	/* next socket in list */
500*7c478bd9Sstevel@tonic-gate } cs_socket_t;
501*7c478bd9Sstevel@tonic-gate 
502*7c478bd9Sstevel@tonic-gate /*
503*7c478bd9Sstevel@tonic-gate  * cs_socket_t->flags flags
504*7c478bd9Sstevel@tonic-gate  */
505*7c478bd9Sstevel@tonic-gate #define	SOCKET_CARD_INSERTED		0x00000001	/* card is inserted */
506*7c478bd9Sstevel@tonic-gate #define	SOCKET_IS_IO			0x00000002	/* socket in IO mode */
507*7c478bd9Sstevel@tonic-gate #define	SOCKET_UNLOAD_MODULE		0x00000004	/* want to unload CS */
508*7c478bd9Sstevel@tonic-gate #define	SOCKET_NEEDS_THREAD		0x00000008	/* wake event thread */
509*7c478bd9Sstevel@tonic-gate #define	SOCKET_IS_VALID			0x00000020	/* socket OK to use */
510*7c478bd9Sstevel@tonic-gate 
511*7c478bd9Sstevel@tonic-gate /*
512*7c478bd9Sstevel@tonic-gate  * cs_socket_t->thread_state and cs_socket_t->ss_thread_state flags
513*7c478bd9Sstevel@tonic-gate  */
514*7c478bd9Sstevel@tonic-gate 
515*7c478bd9Sstevel@tonic-gate /* generic for all threads */
516*7c478bd9Sstevel@tonic-gate #define	SOCKET_THREAD_EXIT		0x00000001	/* exit event thread */
517*7c478bd9Sstevel@tonic-gate 
518*7c478bd9Sstevel@tonic-gate /* only used for per-socket event thread */
519*7c478bd9Sstevel@tonic-gate #define	SOCKET_WAIT_FOR_READY		0x00001000	/* waiting for READY */
520*7c478bd9Sstevel@tonic-gate #define	SOCKET_RESET_TIMER		0x00002000	/* RESET timer */
521*7c478bd9Sstevel@tonic-gate #define	SOCKET_WAIT_SYNC		0x00004000	/* SYNC */
522*7c478bd9Sstevel@tonic-gate 
523*7c478bd9Sstevel@tonic-gate /* only used for Socket Services work thread */
524*7c478bd9Sstevel@tonic-gate #define	SOCKET_THREAD_CSCISInit		0x00100000	/* call CSCISInit */
525*7c478bd9Sstevel@tonic-gate 
526*7c478bd9Sstevel@tonic-gate /*
527*7c478bd9Sstevel@tonic-gate  * cs_socket_t->cis_flags and cs_socket_t->cis_info_t->flags flags
528*7c478bd9Sstevel@tonic-gate  */
529*7c478bd9Sstevel@tonic-gate #define	CW_VALID_CIS			0x00000001	/* valid CIS */
530*7c478bd9Sstevel@tonic-gate #define	CW_MULTI_FUNCTION_CIS		0x00000002	/* multifunction card */
531*7c478bd9Sstevel@tonic-gate #define	CW_LONGLINK_A_FOUND		0x00000004	/* CISTPL_LONGLINK_A */
532*7c478bd9Sstevel@tonic-gate #define	CW_LONGLINK_C_FOUND		0x00000008	/* CISTP_LONGLINK_C */
533*7c478bd9Sstevel@tonic-gate #define	CW_LONGLINK_MFC_FOUND		0x00000010	/* LONGLINK_MFC */
534*7c478bd9Sstevel@tonic-gate #define	CW_CHECK_LINKTARGET		0x00000020	/* check linktarget */
535*7c478bd9Sstevel@tonic-gate #define	CW_RET_ON_LINKTARGET_ERROR	0x00000040	/* linktarget invalid */
536*7c478bd9Sstevel@tonic-gate #define	CW_CHECK_PRIMARY_CHAIN		0x00000080	/* check for primary */
537*7c478bd9Sstevel@tonic-gate 							/* chain tuples */
538*7c478bd9Sstevel@tonic-gate 
539*7c478bd9Sstevel@tonic-gate /*
540*7c478bd9Sstevel@tonic-gate  * CW_LONGLINK_FOUND - a combination of the various CW_LONGLINK_XXX_FOUND
541*7c478bd9Sstevel@tonic-gate  *			flags used to make the code less dense.
542*7c478bd9Sstevel@tonic-gate  */
543*7c478bd9Sstevel@tonic-gate #define	CW_LONGLINK_FOUND		(CW_LONGLINK_A_FOUND |	\
544*7c478bd9Sstevel@tonic-gate 					CW_LONGLINK_C_FOUND |	\
545*7c478bd9Sstevel@tonic-gate 					CW_LONGLINK_MFC_FOUND)
546*7c478bd9Sstevel@tonic-gate 
547*7c478bd9Sstevel@tonic-gate /*
548*7c478bd9Sstevel@tonic-gate  * macro to test for a valid CIS window on a socket
549*7c478bd9Sstevel@tonic-gate  */
550*7c478bd9Sstevel@tonic-gate #define	SOCKET_HAS_CIS_WINDOW(sp)	(sp->cis_win_num != PCMCIA_MAX_WINDOWS)
551*7c478bd9Sstevel@tonic-gate 
552*7c478bd9Sstevel@tonic-gate /*
553*7c478bd9Sstevel@tonic-gate  * cs_socket_t->init_state flags - these flags are used to keep track of what
554*7c478bd9Sstevel@tonic-gate  *	was allocated in cs_init so that things can be deallocated properly
555*7c478bd9Sstevel@tonic-gate  *	in cs_deinit.
556*7c478bd9Sstevel@tonic-gate  */
557*7c478bd9Sstevel@tonic-gate #define	SOCKET_INIT_STATE_MUTEX		0x00000001	/* mutexii are OK */
558*7c478bd9Sstevel@tonic-gate #define	SOCKET_INIT_STATE_CV		0x00000002	/* cvii are OK */
559*7c478bd9Sstevel@tonic-gate #define	SOCKET_INIT_STATE_THREAD	0x00000004	/* thread OK */
560*7c478bd9Sstevel@tonic-gate #define	SOCKET_INIT_STATE_READY		0x00000008	/* socket OK */
561*7c478bd9Sstevel@tonic-gate #define	SOCKET_INIT_STATE_SS_THREAD	0x00000010	/* SS thread OK */
562*7c478bd9Sstevel@tonic-gate /*
563*7c478bd9Sstevel@tonic-gate  * While this next flag doesn't really describe a per-socket resource,
564*7c478bd9Sstevel@tonic-gate  *	we still set it for each socket.  When the soft interrupt handler
565*7c478bd9Sstevel@tonic-gate  *	finally gets removed in cs_deinit, this flag will get cleared.
566*7c478bd9Sstevel@tonic-gate  *	The value of this flag should follow the previous SOCKET_INIT
567*7c478bd9Sstevel@tonic-gate  *	flag values.
568*7c478bd9Sstevel@tonic-gate  */
569*7c478bd9Sstevel@tonic-gate #define	SOCKET_INIT_STATE_SOFTINTR	0x00000020	/* softintr handler */
570*7c478bd9Sstevel@tonic-gate 
571*7c478bd9Sstevel@tonic-gate /*
572*7c478bd9Sstevel@tonic-gate  * Macro to create a socket event thread.
573*7c478bd9Sstevel@tonic-gate  */
574*7c478bd9Sstevel@tonic-gate #define	CS_THREAD_PRIORITY		(v.v_maxsyspri - 4)
575*7c478bd9Sstevel@tonic-gate #define	CREATE_SOCKET_EVENT_THREAD(eh, csp)			\
576*7c478bd9Sstevel@tonic-gate 	thread_create(NULL, 0, eh, (void *)csp,			\
577*7c478bd9Sstevel@tonic-gate 	0, &p0, TS_RUN, CS_THREAD_PRIORITY)
578*7c478bd9Sstevel@tonic-gate 
579*7c478bd9Sstevel@tonic-gate /*
580*7c478bd9Sstevel@tonic-gate  * The per-window structure.
581*7c478bd9Sstevel@tonic-gate  */
582*7c478bd9Sstevel@tonic-gate typedef struct cs_window_t {
583*7c478bd9Sstevel@tonic-gate 	uint32_t	window_num;	/* window number */
584*7c478bd9Sstevel@tonic-gate 	window_handle_t	window_handle;	/* unique window handle */
585*7c478bd9Sstevel@tonic-gate 	client_handle_t	client_handle;	/* owner of this window */
586*7c478bd9Sstevel@tonic-gate 	unsigned	socket_num;	/* socket number */
587*7c478bd9Sstevel@tonic-gate 	unsigned	state;		/* window state flags */
588*7c478bd9Sstevel@tonic-gate 	struct cs_window_t	*next;	/* next window in list */
589*7c478bd9Sstevel@tonic-gate } cs_window_t;
590*7c478bd9Sstevel@tonic-gate 
591*7c478bd9Sstevel@tonic-gate /*
592*7c478bd9Sstevel@tonic-gate  * Window structure state flags - if none of the bits in the
593*7c478bd9Sstevel@tonic-gate  *	CW_WIN_IN_USE mask are set AND if CW_WINDOW_VALID is set,
594*7c478bd9Sstevel@tonic-gate  *	it means that this window is available and not being used
595*7c478bd9Sstevel@tonic-gate  *	by anyone.
596*7c478bd9Sstevel@tonic-gate  * Setting the CW_ALLOCATED will prevent the window from being found
597*7c478bd9Sstevel@tonic-gate  *	as an available window for memory or IO; since memory windows
598*7c478bd9Sstevel@tonic-gate  *	are not shared between clients, RequestWindow will always set
599*7c478bd9Sstevel@tonic-gate  *	the CW_ALLOCATED flag when it has assigned a memory window to
600*7c478bd9Sstevel@tonic-gate  *	a client.  Since we can sometimes share IO windows, RequestIO
601*7c478bd9Sstevel@tonic-gate  *	will only set the CW_ALLOCATED flag if it doesn't want the IO
602*7c478bd9Sstevel@tonic-gate  *	window to be used by other calls to RequestIO.
603*7c478bd9Sstevel@tonic-gate  * When CW_WINDOW_VALID is set, it means that this is a valid window
604*7c478bd9Sstevel@tonic-gate  *	that has been added by the framework and can be used. If this
605*7c478bd9Sstevel@tonic-gate  *	bit is not set, this window can not be used at all.
606*7c478bd9Sstevel@tonic-gate  */
607*7c478bd9Sstevel@tonic-gate #define	CW_ALLOCATED	0x00000001	/* window is allocated  */
608*7c478bd9Sstevel@tonic-gate #define	CW_CIS		0x00000002	/* window being used as CIS window */
609*7c478bd9Sstevel@tonic-gate #define	CW_MEM		0x00000004	/* window being used as mem window */
610*7c478bd9Sstevel@tonic-gate #define	CW_IO		0x00000008	/* window being used as IO window */
611*7c478bd9Sstevel@tonic-gate #define	CW_WIN_IN_USE	0x0000ffff	/* window in use mask */
612*7c478bd9Sstevel@tonic-gate #define	CW_WINDOW_VALID	0x00010000	/* window is valid */
613*7c478bd9Sstevel@tonic-gate 
614*7c478bd9Sstevel@tonic-gate /*
615*7c478bd9Sstevel@tonic-gate  * window handle defines - the WINDOW_HANDLE_MASK implies the maximum number
616*7c478bd9Sstevel@tonic-gate  *	of windows allowed
617*7c478bd9Sstevel@tonic-gate  */
618*7c478bd9Sstevel@tonic-gate #define	WINDOW_HANDLE_MAGIC	0x574d0000
619*7c478bd9Sstevel@tonic-gate #define	WINDOW_HANDLE_MASK	0x0000ffff
620*7c478bd9Sstevel@tonic-gate #define	GET_WINDOW_NUMBER(wh)	((wh) & WINDOW_HANDLE_MASK)
621*7c478bd9Sstevel@tonic-gate #define	GET_WINDOW_MAGIC(wh)	((wh) & ~WINDOW_HANDLE_MASK)
622*7c478bd9Sstevel@tonic-gate 
623*7c478bd9Sstevel@tonic-gate /*
624*7c478bd9Sstevel@tonic-gate  * The client type structures, used to sequence events to clients on a
625*7c478bd9Sstevel@tonic-gate  *	socket. The "type" flags are the same as are used for the
626*7c478bd9Sstevel@tonic-gate  *	RegisterClient function.
627*7c478bd9Sstevel@tonic-gate  */
628*7c478bd9Sstevel@tonic-gate typedef struct client_types_t {
629*7c478bd9Sstevel@tonic-gate 	uint32_t		type;
630*7c478bd9Sstevel@tonic-gate 	uint32_t		order;
631*7c478bd9Sstevel@tonic-gate 	struct client_types_t	*next;
632*7c478bd9Sstevel@tonic-gate } client_types_t;
633*7c478bd9Sstevel@tonic-gate 
634*7c478bd9Sstevel@tonic-gate /*
635*7c478bd9Sstevel@tonic-gate  * Flags that specify the order of client event notifications for the
636*7c478bd9Sstevel@tonic-gate  *	client_types_t structure.
637*7c478bd9Sstevel@tonic-gate  */
638*7c478bd9Sstevel@tonic-gate #define	CLIENT_EVENTS_LIFO	0x00000001
639*7c478bd9Sstevel@tonic-gate #define	CLIENT_EVENTS_FIFO	0x00000002
640*7c478bd9Sstevel@tonic-gate 
641*7c478bd9Sstevel@tonic-gate /*
642*7c478bd9Sstevel@tonic-gate  * This is a structure that CS uses to keep track of items that are global
643*7c478bd9Sstevel@tonic-gate  *	to all functions in the module.
644*7c478bd9Sstevel@tonic-gate  */
645*7c478bd9Sstevel@tonic-gate typedef struct cs_globals_t {
646*7c478bd9Sstevel@tonic-gate 	cs_socket_t	*sp;		/* head of socket list */
647*7c478bd9Sstevel@tonic-gate 	cs_window_t	*cw;		/* head of window list */
648*7c478bd9Sstevel@tonic-gate 	kmutex_t	global_lock;	/* protects this struct */
649*7c478bd9Sstevel@tonic-gate 	kmutex_t	window_lock;	/* protects cs_windows */
650*7c478bd9Sstevel@tonic-gate 	ddi_softintr_t	softint_id;	/* soft interrupt handler id */
651*7c478bd9Sstevel@tonic-gate 	timeout_id_t	sotfint_tmo;	/* soft interrupt handler timeout id */
652*7c478bd9Sstevel@tonic-gate 	uint32_t	init_state;	/* flags set in cs_init */
653*7c478bd9Sstevel@tonic-gate 	uint32_t	flags;		/* general global flags */
654*7c478bd9Sstevel@tonic-gate 	uint32_t	max_socket_num;	/* highest socket number plus one */
655*7c478bd9Sstevel@tonic-gate 	uint32_t	num_sockets;	/* total number of sockets */
656*7c478bd9Sstevel@tonic-gate 	uint32_t	num_windows;	/* total number of windows */
657*7c478bd9Sstevel@tonic-gate 	struct sclient_list_t	*sclient_list;
658*7c478bd9Sstevel@tonic-gate } cs_globals_t;
659*7c478bd9Sstevel@tonic-gate 
660*7c478bd9Sstevel@tonic-gate /*
661*7c478bd9Sstevel@tonic-gate  * Flags for cs_globals_t->init_state
662*7c478bd9Sstevel@tonic-gate  */
663*7c478bd9Sstevel@tonic-gate #define	GLOBAL_INIT_STATE_SOFTINTR	0x00010000	/* softintr handler */
664*7c478bd9Sstevel@tonic-gate #define	GLOBAL_INIT_STATE_MUTEX		0x00020000	/* global mutex init */
665*7c478bd9Sstevel@tonic-gate #define	GLOBAL_INIT_STATE_NO_CLIENTS	0x00040000	/* no new clients */
666*7c478bd9Sstevel@tonic-gate #define	GLOBAL_INIT_STATE_UNLOADING	0x00080000	/* cs_deinit running */
667*7c478bd9Sstevel@tonic-gate #define	GLOBAL_INIT_STATE_SS_READY	0x00100000	/* SS ready for */
668*7c478bd9Sstevel@tonic-gate 							/* callbacks */
669*7c478bd9Sstevel@tonic-gate /*
670*7c478bd9Sstevel@tonic-gate  * Flags for cs_globals_t->flags
671*7c478bd9Sstevel@tonic-gate  */
672*7c478bd9Sstevel@tonic-gate #define	GLOBAL_SUPER_CLIENT_REGISTERED	0x00000001	/* "super-client" reg */
673*7c478bd9Sstevel@tonic-gate #define	GLOBAL_IN_SOFTINTR		0x00000002	/* in soft int code */
674*7c478bd9Sstevel@tonic-gate 
675*7c478bd9Sstevel@tonic-gate /*
676*7c478bd9Sstevel@tonic-gate  * sclient_reg_t struct for RegisterClient when a "super-client" is
677*7c478bd9Sstevel@tonic-gate  *	registering.
678*7c478bd9Sstevel@tonic-gate  * This structure is actually hung off of the client_reg_t.private
679*7c478bd9Sstevel@tonic-gate  *	structure member.  Since we don't make public how to write
680*7c478bd9Sstevel@tonic-gate  *	a "super-client", the actual structure that the client uses
681*7c478bd9Sstevel@tonic-gate  *	is defined in this private header file.
682*7c478bd9Sstevel@tonic-gate  */
683*7c478bd9Sstevel@tonic-gate typedef struct sclient_reg_t {
684*7c478bd9Sstevel@tonic-gate 	uint32_t		max_socket_num;
685*7c478bd9Sstevel@tonic-gate 	uint32_t		num_sockets;
686*7c478bd9Sstevel@tonic-gate 	uint32_t		num_windows;
687*7c478bd9Sstevel@tonic-gate 	uint32_t		num_clients;
688*7c478bd9Sstevel@tonic-gate 	struct sclient_list_t {
689*7c478bd9Sstevel@tonic-gate 		client_handle_t	client_handle;
690*7c478bd9Sstevel@tonic-gate 		uint32_t	error;
691*7c478bd9Sstevel@tonic-gate 	} **sclient_list;
692*7c478bd9Sstevel@tonic-gate } sclient_reg_t;
693*7c478bd9Sstevel@tonic-gate 
694*7c478bd9Sstevel@tonic-gate /*
695*7c478bd9Sstevel@tonic-gate  * structure for event text used for cs_ss_event_text
696*7c478bd9Sstevel@tonic-gate  */
697*7c478bd9Sstevel@tonic-gate typedef struct cs_ss_event_text_t {
698*7c478bd9Sstevel@tonic-gate 	event_t		ss_event;	/* SS event code */
699*7c478bd9Sstevel@tonic-gate 	event_t		cs_event;	/* CS event code */
700*7c478bd9Sstevel@tonic-gate 	char		*text;
701*7c478bd9Sstevel@tonic-gate } cs_ss_event_text_t;
702*7c478bd9Sstevel@tonic-gate 
703*7c478bd9Sstevel@tonic-gate /*
704*7c478bd9Sstevel@tonic-gate  * Flags for cs_read_event_status
705*7c478bd9Sstevel@tonic-gate  */
706*7c478bd9Sstevel@tonic-gate #define	CS_RES_IGNORE_NO_CARD		0x0001	/* don't check for card */
707*7c478bd9Sstevel@tonic-gate 
708*7c478bd9Sstevel@tonic-gate /*
709*7c478bd9Sstevel@tonic-gate  * cs_csfunc2text_strings_t structure used internally in Error2Text
710*7c478bd9Sstevel@tonic-gate  */
711*7c478bd9Sstevel@tonic-gate typedef struct cs_csfunc2text_strings_t {
712*7c478bd9Sstevel@tonic-gate 	uint32_t	item;
713*7c478bd9Sstevel@tonic-gate 	char		*text;
714*7c478bd9Sstevel@tonic-gate } cs_csfunc2text_strings_t;
715*7c478bd9Sstevel@tonic-gate 
716*7c478bd9Sstevel@tonic-gate /*
717*7c478bd9Sstevel@tonic-gate  * Flags for Error2Text - not used by clients; the struct is defined
718*7c478bd9Sstevel@tonic-gate  *	in the cs.h header file.
719*7c478bd9Sstevel@tonic-gate  */
720*7c478bd9Sstevel@tonic-gate #define	CSFUN2TEXT_FUNCTION	0x0001	/* return text of CS function code */
721*7c478bd9Sstevel@tonic-gate #define	CSFUN2TEXT_RETURN	0x0002	/* return text of CS return code */
722*7c478bd9Sstevel@tonic-gate 
723*7c478bd9Sstevel@tonic-gate /*
724*7c478bd9Sstevel@tonic-gate  * Macros to walk the local linked CIS list.
725*7c478bd9Sstevel@tonic-gate  *
726*7c478bd9Sstevel@tonic-gate  * These macros can take any valid local list tuple pointer.  They return
727*7c478bd9Sstevel@tonic-gate  *	another tuple pointer or NULL if they fail.
728*7c478bd9Sstevel@tonic-gate  */
729*7c478bd9Sstevel@tonic-gate #define	GET_NEXT_TUPLE(tp, f)		CIS_PARSER(CISP_CIS_GET_LTUPLE, tp,  \
730*7c478bd9Sstevel@tonic-gate 						NULL, GET_NEXT_LTUPLEF |     \
731*7c478bd9Sstevel@tonic-gate 						(f & ~CIS_GET_LTUPLE_OPMASK))
732*7c478bd9Sstevel@tonic-gate #define	GET_PREV_TUPLE(tp, f)		CIS_PARSER(CISP_CIS_GET_LTUPLE, tp,  \
733*7c478bd9Sstevel@tonic-gate 						NULL, GET_PREV_LTUPLEF |     \
734*7c478bd9Sstevel@tonic-gate 						(f & ~CIS_GET_LTUPLE_OPMASK))
735*7c478bd9Sstevel@tonic-gate #define	GET_FIRST_LTUPLE(tp, f)		CIS_PARSER(CISP_CIS_GET_LTUPLE, tp,   \
736*7c478bd9Sstevel@tonic-gate 						NULL, GET_FIRST_LTUPLEF |     \
737*7c478bd9Sstevel@tonic-gate 						(f & ~CIS_GET_LTUPLE_OPMASK))
738*7c478bd9Sstevel@tonic-gate #define	GET_LAST_LTUPLE(tp, f)		CIS_PARSER(CISP_CIS_GET_LTUPLE, tp,   \
739*7c478bd9Sstevel@tonic-gate 						NULL, GET_LAST_LTUPLEF |      \
740*7c478bd9Sstevel@tonic-gate 						(f & ~CIS_GET_LTUPLE_OPMASK))
741*7c478bd9Sstevel@tonic-gate #define	FIND_LTUPLE_FWD(tp, tu, f)	CIS_PARSER(CISP_CIS_GET_LTUPLE, tp,   \
742*7c478bd9Sstevel@tonic-gate 						tu, FIND_LTUPLE_FWDF |        \
743*7c478bd9Sstevel@tonic-gate 						(f & ~CIS_GET_LTUPLE_OPMASK))
744*7c478bd9Sstevel@tonic-gate #define	FIND_LTUPLE_BACK(tp, tu, f)	CIS_PARSER(CISP_CIS_GET_LTUPLE, tp,   \
745*7c478bd9Sstevel@tonic-gate 						tu, FIND_LTUPLE_BACKF |       \
746*7c478bd9Sstevel@tonic-gate 						(f & ~CIS_GET_LTUPLE_OPMASK))
747*7c478bd9Sstevel@tonic-gate #define	FIND_NEXT_LTUPLE(tp, tu, f)	CIS_PARSER(CISP_CIS_GET_LTUPLE, tp,   \
748*7c478bd9Sstevel@tonic-gate 						tu, FIND_NEXT_LTUPLEF |       \
749*7c478bd9Sstevel@tonic-gate 						(f & ~CIS_GET_LTUPLE_OPMASK))
750*7c478bd9Sstevel@tonic-gate #define	FIND_PREV_LTUPLE(tp, tu, f)	CIS_PARSER(CISP_CIS_GET_LTUPLE, tp,   \
751*7c478bd9Sstevel@tonic-gate 						tu, FIND_PREV_LTUPLEF |       \
752*7c478bd9Sstevel@tonic-gate 						(f & ~CIS_GET_LTUPLE_OPMASK))
753*7c478bd9Sstevel@tonic-gate #define	FIND_FIRST_LTUPLE(tp, tu, f)	FIND_LTUPLE_FWD(GET_FIRST_LTUPLE(tp,  \
754*7c478bd9Sstevel@tonic-gate 								f), tu, f)
755*7c478bd9Sstevel@tonic-gate 
756*7c478bd9Sstevel@tonic-gate 
757*7c478bd9Sstevel@tonic-gate /*
758*7c478bd9Sstevel@tonic-gate  * Card Services hooks and general nexus prototypes
759*7c478bd9Sstevel@tonic-gate  */
760*7c478bd9Sstevel@tonic-gate int	 cs_init(void);
761*7c478bd9Sstevel@tonic-gate uint32_t cs_event(event_t, uint32_t, uint32_t);
762*7c478bd9Sstevel@tonic-gate int	 pcmcia_set_em_handler(int (*handler)(), caddr_t events,
763*7c478bd9Sstevel@tonic-gate 	    int elen, uint32_t id, void **cs, void **ss);
764*7c478bd9Sstevel@tonic-gate 
765*7c478bd9Sstevel@tonic-gate extern csfunction_t	*cs_socket_services;
766*7c478bd9Sstevel@tonic-gate 
767*7c478bd9Sstevel@tonic-gate 
768*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
769*7c478bd9Sstevel@tonic-gate }
770*7c478bd9Sstevel@tonic-gate #endif
771*7c478bd9Sstevel@tonic-gate 
772*7c478bd9Sstevel@tonic-gate #endif	/* _CS_PRIV_H */
773