1144966Svkashyap/*
2169400Sscottl * Copyright (c) 2004-07 Applied Micro Circuits Corporation.
3144966Svkashyap * Copyright (c) 2004-05 Vinod Kashyap
4144966Svkashyap * All rights reserved.
5144966Svkashyap *
6144966Svkashyap * Redistribution and use in source and binary forms, with or without
7144966Svkashyap * modification, are permitted provided that the following conditions
8144966Svkashyap * are met:
9144966Svkashyap * 1. Redistributions of source code must retain the above copyright
10144966Svkashyap *    notice, this list of conditions and the following disclaimer.
11144966Svkashyap * 2. Redistributions in binary form must reproduce the above copyright
12144966Svkashyap *    notice, this list of conditions and the following disclaimer in the
13144966Svkashyap *    documentation and/or other materials provided with the distribution.
14144966Svkashyap *
15144966Svkashyap * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16144966Svkashyap * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17144966Svkashyap * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18144966Svkashyap * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19144966Svkashyap * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20144966Svkashyap * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21144966Svkashyap * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22144966Svkashyap * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23144966Svkashyap * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24144966Svkashyap * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25144966Svkashyap * SUCH DAMAGE.
26144966Svkashyap *
27144966Svkashyap *	$FreeBSD$
28144966Svkashyap */
29144966Svkashyap
30144966Svkashyap/*
31144966Svkashyap * AMCC'S 3ware driver for 9000 series storage controllers.
32144966Svkashyap *
33144966Svkashyap * Author: Vinod Kashyap
34169400Sscottl * Modifications by: Adam Radford
35172496Sscottl * Modifications by: Manjunath Ranganathaiah
36144966Svkashyap */
37144966Svkashyap
38144966Svkashyap
39144966Svkashyap
40144966Svkashyap#ifndef TW_CL_SHARE_H
41144966Svkashyap
42144966Svkashyap#define TW_CL_SHARE_H
43144966Svkashyap
44144966Svkashyap
45144966Svkashyap/*
46144966Svkashyap * Macros, structures and functions shared between OSL and CL,
47144966Svkashyap * and defined by CL.
48144966Svkashyap */
49144966Svkashyap
50144966Svkashyap#define TW_CL_NULL			((TW_VOID *)0)
51144966Svkashyap#define TW_CL_TRUE			1
52144966Svkashyap#define TW_CL_FALSE			0
53144966Svkashyap
54144966Svkashyap#define TW_CL_VENDOR_ID			0x13C1	/* 3ware vendor id */
55152213Svkashyap#define TW_CL_DEVICE_ID_9K		0x1002	/* 9000 PCI series device id */
56152213Svkashyap#define TW_CL_DEVICE_ID_9K_X		0x1003	/* 9000 PCI-X series device id */
57169400Sscottl#define TW_CL_DEVICE_ID_9K_E		0x1004  /* 9000 PCIe series device id */
58172496Sscottl#define TW_CL_DEVICE_ID_9K_SA		0x1005	/* 9000 PCIe SAS series device id */
59144966Svkashyap
60152213Svkashyap#define TW_CL_BAR_TYPE_IO		1	/* I/O base address */
61152213Svkashyap#define TW_CL_BAR_TYPE_MEM		2	/* memory base address */
62152213Svkashyap#define TW_CL_BAR_TYPE_SBUF		3	/* SBUF base address */
63152213Svkashyap
64152213Svkashyap#ifdef TW_OSL_ENCLOSURE_SUPPORT
65152213Svkashyap#define TW_CL_MAX_NUM_UNITS		65	/* max # of units we support
66152213Svkashyap						-- enclosure target id is 64 */
67152213Svkashyap#else /* TW_OSL_ENCLOSURE_SUPPORT */
68169400Sscottl#define TW_CL_MAX_NUM_UNITS		32	/* max # of units we support */
69152213Svkashyap#endif /* TW_OSL_ENCLOSURE_SUPPORT */
70152213Svkashyap
71144966Svkashyap#define TW_CL_MAX_NUM_LUNS		16	/* max # of LUN's we support */
72144966Svkashyap#define TW_CL_MAX_IO_SIZE		0x20000	/* 128K */
73144966Svkashyap
74144966Svkashyap/*
75144966Svkashyap * Though we can support 256 simultaneous requests, we advertise as capable
76144966Svkashyap * of supporting only 255, since we want to keep one CL internal request
77144966Svkashyap * context packet always available for internal requests.
78144966Svkashyap */
79208969Sdelphij#define TW_CL_MAX_SIMULTANEOUS_REQUESTS	256	/* max simult reqs supported */
80144966Svkashyap
81144966Svkashyap#define TW_CL_MAX_32BIT_SG_ELEMENTS	109	/* max 32-bit sg elements */
82144966Svkashyap#define TW_CL_MAX_64BIT_SG_ELEMENTS	72	/* max 64-bit sg elements */
83144966Svkashyap
84144966Svkashyap
85144966Svkashyap/* Possible values of ctlr->flags */
86144966Svkashyap#define TW_CL_64BIT_ADDRESSES	(1<<0) /* 64 bit cmdpkt & SG addresses */
87144966Svkashyap#define TW_CL_64BIT_SG_LENGTH	(1<<1) /* 64 bit SG length */
88144966Svkashyap#define TW_CL_START_CTLR_ONLY	(1<<2) /* Start ctlr only */
89144966Svkashyap#define TW_CL_STOP_CTLR_ONLY	(1<<3) /* Stop ctlr only */
90152213Svkashyap#define TW_CL_DEFERRED_INTR_USED (1<<5) /* OS Layer uses deferred intr */
91144966Svkashyap
92144966Svkashyap/* Possible error values from the Common Layer. */
93144966Svkashyap#define TW_CL_ERR_REQ_SUCCESS			0
94144966Svkashyap#define TW_CL_ERR_REQ_GENERAL_FAILURE		(1<<0)
95144966Svkashyap#define TW_CL_ERR_REQ_INVALID_TARGET		(1<<1)
96144966Svkashyap#define TW_CL_ERR_REQ_INVALID_LUN		(1<<2)
97144966Svkashyap#define TW_CL_ERR_REQ_SCSI_ERROR		(1<<3)
98144966Svkashyap#define TW_CL_ERR_REQ_AUTO_SENSE_VALID		(1<<4)
99144966Svkashyap#define TW_CL_ERR_REQ_BUS_RESET			(1<<5)
100144966Svkashyap#define TW_CL_ERR_REQ_UNABLE_TO_SUBMIT_COMMAND	(1<<6)
101144966Svkashyap
102144966Svkashyap
103144966Svkashyap/* Possible values of req_pkt->flags */
104144966Svkashyap#define TW_CL_REQ_RETRY_ON_BUSY		(1<<0)
105144966Svkashyap#define TW_CL_REQ_CALLBACK_FOR_SGLIST	(1<<1)
106144966Svkashyap
107144966Svkashyap
108144966Svkashyap#define TW_CL_MESSAGE_SOURCE_CONTROLLER_ERROR	3
109144966Svkashyap#define TW_CL_MESSAGE_SOURCE_CONTROLLER_EVENT	4
110144966Svkashyap#define TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR	21
111144966Svkashyap#define TW_CL_MESSAGE_SOURCE_COMMON_LAYER_EVENT	22
112144966Svkashyap#define TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER	5
113144966Svkashyap#define TW_CL_MESSAGE_SOURCE_FREEBSD_OS		8
114144966Svkashyap#define TW_CL_MESSAGE_SOURCE_WINDOWS_DRIVER	7
115144966Svkashyap#define TW_CL_MESSAGE_SOURCE_WINDOWS_OS		10
116144966Svkashyap
117144966Svkashyap#define TW_CL_SEVERITY_ERROR		0x1
118144966Svkashyap#define TW_CL_SEVERITY_WARNING		0x2
119144966Svkashyap#define TW_CL_SEVERITY_INFO		0x3
120144966Svkashyap#define TW_CL_SEVERITY_DEBUG		0x4
121144966Svkashyap
122144966Svkashyap#define TW_CL_SEVERITY_ERROR_STRING	"ERROR"
123144966Svkashyap#define TW_CL_SEVERITY_WARNING_STRING	"WARNING"
124144966Svkashyap#define TW_CL_SEVERITY_INFO_STRING	"INFO"
125144966Svkashyap#define TW_CL_SEVERITY_DEBUG_STRING	"DEBUG"
126144966Svkashyap
127144966Svkashyap
128144966Svkashyap
129144966Svkashyap/*
130144966Svkashyap * Structure, a pointer to which is used as the controller handle in
131144966Svkashyap * communications between the OS Layer and the Common Layer.
132144966Svkashyap */
133144966Svkashyapstruct tw_cl_ctlr_handle {
134144966Svkashyap	TW_VOID	*osl_ctlr_ctxt;	/* OSL's ctlr context */
135144966Svkashyap	TW_VOID	*cl_ctlr_ctxt;	/* CL's ctlr context */
136144966Svkashyap};
137144966Svkashyap
138144966Svkashyap
139144966Svkashyap/*
140144966Svkashyap * Structure, a pointer to which is used as the request handle in
141144966Svkashyap * communications between the OS Layer and the Common Layer.
142144966Svkashyap */
143144966Svkashyapstruct tw_cl_req_handle {
144144966Svkashyap	TW_VOID	*osl_req_ctxt;	/* OSL's request context */
145144966Svkashyap	TW_VOID	*cl_req_ctxt;	/* CL's request context */
146208969Sdelphij	TW_UINT8 is_io;		/* Only freeze/release simq for IOs */
147144966Svkashyap};
148144966Svkashyap
149144966Svkashyap
150144966Svkashyap/* Structure used to describe SCSI requests to CL. */
151144966Svkashyapstruct tw_cl_scsi_req_packet {
152144966Svkashyap	TW_UINT32	unit;		/* unit # to send cmd to */
153144966Svkashyap	TW_UINT32	lun;		/* LUN to send cmd to */
154144966Svkashyap	TW_UINT8	*cdb;		/* ptr to SCSI cdb */
155144966Svkashyap	TW_UINT32	cdb_len;	/* # of valid cdb bytes */
156144966Svkashyap	TW_UINT32	sense_len;	/* # of bytes of valid sense info */
157144966Svkashyap	TW_UINT8	*sense_data;	/* ptr to sense data, if any */
158144966Svkashyap	TW_UINT32	scsi_status;	/* SCSI status returned by fw */
159144966Svkashyap	TW_UINT32	sgl_entries;	/* # of SG descriptors */
160144966Svkashyap	TW_UINT8	*sg_list;	/* ptr to SG list */
161144966Svkashyap};
162144966Svkashyap
163144966Svkashyap
164144966Svkashyap/* Structure used to describe pass through command packets to CL. */
165144966Svkashyapstruct tw_cl_passthru_req_packet {
166144966Svkashyap	TW_UINT8	*cmd_pkt;	/* ptr to passthru cmd pkt */
167144966Svkashyap	TW_UINT32	cmd_pkt_length;	/* size of cmd pkt */
168144966Svkashyap	TW_UINT32	sgl_entries;	/* # of SG descriptors */
169144966Svkashyap	TW_UINT8	*sg_list;	/* ptr to SG list */
170144966Svkashyap};
171144966Svkashyap
172144966Svkashyap
173144966Svkashyap/* Request packet submitted to the Common Layer, by the OS Layer. */
174144966Svkashyapstruct tw_cl_req_packet {
175144966Svkashyap	TW_UINT32	cmd;		/* Common Layer cmd */
176144966Svkashyap	TW_UINT32	flags;		/* flags describing request */
177144966Svkashyap	TW_UINT32	status;		/* Common Layer returned status */
178144966Svkashyap	TW_VOID		(*tw_osl_callback)(struct tw_cl_req_handle *req_handle);
179144966Svkashyap			/* OSL routine to be called by CL on req completion */
180144966Svkashyap	TW_VOID		(*tw_osl_sgl_callback)(
181144966Svkashyap			struct tw_cl_req_handle *req_handle, TW_VOID *sg_list,
182144966Svkashyap			TW_UINT32 *num_sgl_entries);
183144966Svkashyap			/* OSL callback to get SG list. */
184144966Svkashyap
185144966Svkashyap	union {
186144966Svkashyap		struct tw_cl_scsi_req_packet		scsi_req; /* SCSI req */
187144966Svkashyap		struct tw_cl_passthru_req_packet	pt_req;/*Passthru req*/
188144966Svkashyap	} gen_req_pkt;
189144966Svkashyap};
190144966Svkashyap
191144966Svkashyap
192209860Sdelphij#pragma pack(1)
193144966Svkashyap/*
194144966Svkashyap * Packet that describes an AEN/error generated by the controller,
195144966Svkashyap * Common Layer, or even the OS Layer.
196144966Svkashyap */
197144966Svkashyapstruct tw_cl_event_packet {
198144966Svkashyap	TW_UINT32	sequence_id;
199144966Svkashyap	TW_UINT32	time_stamp_sec;
200144966Svkashyap	TW_UINT16	aen_code;
201144966Svkashyap	TW_UINT8	severity;
202144966Svkashyap	TW_UINT8	retrieved;
203144966Svkashyap	TW_UINT8	repeat_count;
204144966Svkashyap	TW_UINT8	parameter_len;
205144966Svkashyap	TW_UINT8	parameter_data[98];
206144966Svkashyap	TW_UINT32	event_src;
207144966Svkashyap	TW_UINT8	severity_str[20];
208144966Svkashyap};
209209860Sdelphij#pragma pack()
210144966Svkashyap
211144966Svkashyap
212144966Svkashyap/* Structure to link 2 adjacent elements in a list. */
213144966Svkashyapstruct tw_cl_link {
214144966Svkashyap	struct tw_cl_link	*next;
215144966Svkashyap	struct tw_cl_link	*prev;
216144966Svkashyap};
217144966Svkashyap
218144966Svkashyap
219209860Sdelphij#pragma pack(1)
220144966Svkashyap/* Scatter/Gather list entry with 32 bit addresses. */
221144966Svkashyapstruct tw_cl_sg_desc32 {
222144966Svkashyap	TW_UINT32	address;
223144966Svkashyap	TW_UINT32	length;
224144966Svkashyap};
225144966Svkashyap
226144966Svkashyap
227144966Svkashyap/* Scatter/Gather list entry with 64 bit addresses. */
228144966Svkashyapstruct tw_cl_sg_desc64 {
229144966Svkashyap	TW_UINT64	address;
230144966Svkashyap	TW_UINT32	length;
231144966Svkashyap};
232144966Svkashyap
233144966Svkashyap#pragma pack()
234144966Svkashyap
235144966Svkashyap
236144966Svkashyap/* Byte swap functions.  Valid only if running on big endian platforms. */
237144966Svkashyap#ifdef TW_OSL_BIG_ENDIAN
238144966Svkashyap
239144966Svkashyap#define TW_CL_SWAP16_WITH_CAST(x)					\
240144966Svkashyap	((x << 8) | (x >> 8))
241144966Svkashyap
242144966Svkashyap
243144966Svkashyap#define TW_CL_SWAP32_WITH_CAST(x)					\
244144966Svkashyap	((x << 24) | ((x << 8) & (0xFF0000)) |				\
245144966Svkashyap	((x >> 8) & (0xFF00)) | (x >> 24))
246144966Svkashyap
247144966Svkashyap
248144966Svkashyap#define TW_CL_SWAP64_WITH_CAST(x)					\
249144966Svkashyap	((((TW_UINT64)(TW_CL_SWAP32(((TW_UINT32 *)(&(x)))[1]))) << 32) |\
250144966Svkashyap	((TW_UINT32)(TW_CL_SWAP32(((TW_UINT32 *)(&(x)))[0]))))
251144966Svkashyap
252144966Svkashyap
253144966Svkashyap#else /* TW_OSL_BIG_ENDIAN */
254144966Svkashyap
255144966Svkashyap#define TW_CL_SWAP16_WITH_CAST(x)	x
256144966Svkashyap#define TW_CL_SWAP32_WITH_CAST(x)	x
257144966Svkashyap#define TW_CL_SWAP64_WITH_CAST(x)	x
258144966Svkashyap
259144966Svkashyap#endif /* TW_OSL_BIG_ENDIAN */
260144966Svkashyap
261144966Svkashyap#define TW_CL_SWAP16(x)		TW_CL_SWAP16_WITH_CAST((TW_UINT16)(x))
262144966Svkashyap#define TW_CL_SWAP32(x)		TW_CL_SWAP32_WITH_CAST((TW_UINT32)(x))
263144966Svkashyap#define TW_CL_SWAP64(x)		TW_CL_SWAP64_WITH_CAST((TW_UINT64)(x))
264144966Svkashyap
265144966Svkashyap
266144966Svkashyap/* Queue manipulation functions. */
267144966Svkashyap
268144966Svkashyap/* Initialize a queue. */
269144966Svkashyap#define TW_CL_Q_INIT(head)	do {		\
270144966Svkashyap	(head)->prev = (head)->next = head;	\
271144966Svkashyap} while (0)
272144966Svkashyap
273144966Svkashyap
274144966Svkashyap/* Insert an item at the head of the queue. */
275144966Svkashyap#define TW_CL_Q_INSERT_HEAD(head, item)	do {	\
276144966Svkashyap	(item)->next = (head)->next;		\
277144966Svkashyap	(item)->prev = head;			\
278144966Svkashyap	(head)->next->prev = item;		\
279144966Svkashyap	(head)->next = item;			\
280144966Svkashyap} while (0)
281144966Svkashyap
282144966Svkashyap
283144966Svkashyap/* Insert an item at the tail of the queue. */
284144966Svkashyap#define	TW_CL_Q_INSERT_TAIL(head, item)	do {	\
285144966Svkashyap	(item)->next = head;			\
286144966Svkashyap	(item)->prev = (head)->prev;		\
287144966Svkashyap	(head)->prev->next = item;		\
288144966Svkashyap	(head)->prev = item;			\
289144966Svkashyap} while (0)
290144966Svkashyap
291144966Svkashyap
292144966Svkashyap/* Remove an item from the head of the queue. */
293144966Svkashyap#define TW_CL_Q_REMOVE_ITEM(head, item)	do {	\
294144966Svkashyap	(item)->prev->next = (item)->next;	\
295144966Svkashyap	(item)->next->prev = (item)->prev;	\
296144966Svkashyap} while (0)
297144966Svkashyap
298144966Svkashyap
299144966Svkashyap/* Retrieve the item at the head of the queue. */
300144966Svkashyap#define TW_CL_Q_FIRST_ITEM(head)		\
301144966Svkashyap	(((head)->next != head) ? ((head)->next) : TW_CL_NULL)
302144966Svkashyap
303144966Svkashyap
304144966Svkashyap/* Retrieve the item at the tail of the queue. */
305144966Svkashyap#define TW_CL_Q_LAST_ITEM(head)			\
306144966Svkashyap	(((head)->prev != head) ? ((head)->prev) : TW_CL_NULL)
307144966Svkashyap
308144966Svkashyap
309144966Svkashyap/* Retrieve the item next to a given item in the queue. */
310144966Svkashyap#define TW_CL_Q_NEXT_ITEM(head, item)		\
311144966Svkashyap	(((item)->next != head) ? ((item)->next) : TW_CL_NULL)
312144966Svkashyap
313144966Svkashyap
314144966Svkashyap/* Retrieve the item previous to a given item in the queue. */
315144966Svkashyap#define TW_CL_Q_PREV_ITEM(head, item)		\
316144966Svkashyap	(((item)->prev != head) ? ((item)->prev) : TW_CL_NULL)
317144966Svkashyap
318144966Svkashyap
319144966Svkashyap/* Determine the offset of a field from the head of the structure it is in. */
320144966Svkashyap#define	TW_CL_STRUCT_OFFSET(struct_type, field)	\
321144966Svkashyap	(TW_INT8 *)(&((struct_type *)0)->field)
322144966Svkashyap
323144966Svkashyap
324144966Svkashyap/*
325144966Svkashyap * Determine the address of the head of a structure, given the address of a
326144966Svkashyap * field within it.
327144966Svkashyap */
328144966Svkashyap#define TW_CL_STRUCT_HEAD(addr, struct_type, field)	\
329144966Svkashyap	(struct_type *)((TW_INT8 *)addr -		\
330144966Svkashyap	TW_CL_STRUCT_OFFSET(struct_type, field))
331144966Svkashyap
332144966Svkashyap
333144966Svkashyap
334152213Svkashyap#ifndef TW_BUILDING_API
335152213Svkashyap
336152213Svkashyap#include "tw_osl_inline.h"
337152213Svkashyap
338152213Svkashyap
339152213Svkashyap
340144966Svkashyap/*
341144966Svkashyap * The following are extern declarations of OS Layer defined functions called
342144966Svkashyap * by the Common Layer.  If any function has been defined as a macro in
343144966Svkashyap * tw_osl_share.h, we will not make the extern declaration here.
344144966Svkashyap */
345144966Svkashyap
346144966Svkashyap#ifndef tw_osl_breakpoint
347144966Svkashyap/* Allows setting breakpoints in the CL code for debugging purposes. */
348144966Svkashyapextern TW_VOID	tw_osl_breakpoint(TW_VOID);
349144966Svkashyap#endif
350144966Svkashyap
351144966Svkashyap
352212008Sdelphij#ifndef tw_osl_timeout
353212008Sdelphij/* Start OS timeout() routine after controller reset sequence */
354212008Sdelphijextern TW_VOID	tw_osl_timeout(struct tw_cl_req_handle *req_handle);
355152213Svkashyap#endif
356152213Svkashyap
357212008Sdelphij#ifndef tw_osl_untimeout
358212008Sdelphij/* Stop OS timeout() routine during controller reset sequence */
359212008Sdelphijextern TW_VOID	tw_osl_untimeout(struct tw_cl_req_handle *req_handle);
360212008Sdelphij#endif
361152213Svkashyap
362212008Sdelphij
363144966Svkashyap#ifndef tw_osl_cur_func
364144966Svkashyap/* Text name of current function. */
365144966Svkashyapextern TW_INT8	*tw_osl_cur_func(TW_VOID);
366144966Svkashyap#endif
367144966Svkashyap
368144966Svkashyap
369144966Svkashyap#ifdef TW_OSL_DEBUG
370144966Svkashyap#ifndef tw_osl_dbg_printf
371144966Svkashyap/* Print to syslog/event log/debug console, as applicable. */
372144966Svkashyapextern TW_INT32 tw_osl_dbg_printf(struct tw_cl_ctlr_handle *ctlr_handle,
373144966Svkashyap	const TW_INT8 *fmt, ...);
374144966Svkashyap#endif
375144966Svkashyap#endif /* TW_OSL_DEBUG */
376144966Svkashyap
377144966Svkashyap
378144966Svkashyap#ifndef tw_osl_delay
379144966Svkashyap/* Cause a delay of usecs micro-seconds. */
380144966Svkashyapextern TW_VOID	tw_osl_delay(TW_INT32 usecs);
381144966Svkashyap#endif
382144966Svkashyap
383144966Svkashyap
384144966Svkashyap#ifndef tw_osl_destroy_lock
385144966Svkashyap/* Create/initialize a lock for CL's use. */
386144966Svkashyapextern TW_VOID	tw_osl_destroy_lock(struct tw_cl_ctlr_handle *ctlr_handle,
387144966Svkashyap	TW_LOCK_HANDLE *lock);
388144966Svkashyap#endif
389144966Svkashyap
390144966Svkashyap
391144966Svkashyap#ifndef tw_osl_free_lock
392144966Svkashyap/* Free a previously held lock. */
393144966Svkashyapextern TW_VOID	tw_osl_free_lock(struct tw_cl_ctlr_handle *ctlr_handle,
394144966Svkashyap	TW_LOCK_HANDLE *lock);
395144966Svkashyap#endif
396144966Svkashyap
397144966Svkashyap
398144966Svkashyap#ifndef tw_osl_get_local_time
399144966Svkashyap/* Get local time. */
400144966Svkashyapextern TW_TIME	tw_osl_get_local_time(TW_VOID);
401144966Svkashyap#endif
402144966Svkashyap
403144966Svkashyap
404144966Svkashyap#ifndef tw_osl_get_lock
405144966Svkashyap/* Acquire a lock. */
406144966Svkashyapextern TW_VOID	tw_osl_get_lock(struct tw_cl_ctlr_handle *ctlr_handle,
407144966Svkashyap	TW_LOCK_HANDLE *lock);
408144966Svkashyap#endif
409144966Svkashyap
410144966Svkashyap
411144966Svkashyap#ifndef tw_osl_init_lock
412144966Svkashyap/* Create/initialize a lock for CL's use. */
413144966Svkashyapextern TW_VOID	tw_osl_init_lock(struct tw_cl_ctlr_handle *ctlr_handle,
414144966Svkashyap	TW_INT8 *lock_name, TW_LOCK_HANDLE *lock);
415144966Svkashyap#endif
416144966Svkashyap
417144966Svkashyap
418144966Svkashyap#ifndef tw_osl_memcpy
419144966Svkashyap/* Copy 'size' bytes from 'src' to 'dest'. */
420144966Svkashyapextern TW_VOID	tw_osl_memcpy(TW_VOID *src, TW_VOID *dest, TW_INT32 size);
421144966Svkashyap#endif
422144966Svkashyap
423144966Svkashyap
424144966Svkashyap#ifndef tw_osl_memzero
425144966Svkashyap/* Zero 'size' bytes starting at 'addr'. */
426144966Svkashyapextern TW_VOID	tw_osl_memzero(TW_VOID *addr, TW_INT32 size);
427144966Svkashyap#endif
428144966Svkashyap
429144966Svkashyap
430144966Svkashyap#ifndef tw_osl_notify_event
431144966Svkashyap/* Notify OSL of a controller/CL (or even OSL) event. */
432144966Svkashyapextern TW_VOID	tw_osl_notify_event(struct tw_cl_ctlr_handle *ctlr_handle,
433144966Svkashyap	struct tw_cl_event_packet *event);
434144966Svkashyap#endif
435144966Svkashyap
436144966Svkashyap
437144966Svkashyap#ifdef TW_OSL_PCI_CONFIG_ACCESSIBLE
438144966Svkashyap#ifndef tw_osl_read_pci_config
439144966Svkashyap/* Read 'size' bytes from 'offset' in the PCI config space. */
440144966Svkashyapextern TW_UINT32 tw_osl_read_pci_config(
441144966Svkashyap	struct tw_cl_ctlr_handle *ctlr_handle, TW_INT32 offset, TW_INT32 size);
442144966Svkashyap#endif
443144966Svkashyap#endif /* TW_OSL_PCI_CONFIG_ACCESSIBLE */
444144966Svkashyap
445144966Svkashyap
446144966Svkashyap#ifndef tw_osl_read_reg
447144966Svkashyap/* Read 'size' bytes at 'offset' from base address of this controller. */
448144966Svkashyapextern TW_UINT32 tw_osl_read_reg(struct tw_cl_ctlr_handle *ctlr_handle,
449144966Svkashyap	TW_INT32 offset, TW_INT32 size);
450144966Svkashyap#endif
451144966Svkashyap
452144966Svkashyap
453144966Svkashyap#ifndef tw_osl_scan_bus
454144966Svkashyap/* Request OSL for a bus scan. */
455144966Svkashyapextern TW_VOID	tw_osl_scan_bus(struct tw_cl_ctlr_handle *ctlr_handle);
456144966Svkashyap#endif
457144966Svkashyap
458144966Svkashyap
459144966Svkashyap#ifdef TW_OSL_CAN_SLEEP
460144966Svkashyap#ifndef tw_osl_sleep
461144966Svkashyap/* Sleep for 'timeout' ms or until woken up (by tw_osl_wakeup). */
462144966Svkashyapextern TW_INT32	tw_osl_sleep(struct tw_cl_ctlr_handle *ctlr_handle,
463144966Svkashyap	TW_SLEEP_HANDLE *sleep_handle, TW_INT32 timeout);
464144966Svkashyap#endif
465144966Svkashyap#endif /* TW_OSL_CAN_SLEEP */
466144966Svkashyap
467144966Svkashyap
468144966Svkashyap#ifndef tw_osl_sprintf
469144966Svkashyap/* Standard sprintf. */
470144966Svkashyapextern TW_INT32	tw_osl_sprintf(TW_INT8 *dest, const TW_INT8 *fmt, ...);
471144966Svkashyap#endif
472144966Svkashyap
473144966Svkashyap
474144966Svkashyap#ifndef tw_osl_strcpy
475144966Svkashyap/* Copy string 'src' to 'dest'. */
476144966Svkashyapextern TW_INT8	*tw_osl_strcpy(TW_INT8 *dest, TW_INT8 *src);
477144966Svkashyap#endif
478144966Svkashyap
479144966Svkashyap
480144966Svkashyap#ifndef tw_osl_strlen
481144966Svkashyap/* Return length of string pointed at by 'str'. */
482144966Svkashyapextern TW_INT32	tw_osl_strlen(TW_VOID *str);
483144966Svkashyap#endif
484144966Svkashyap
485152213Svkashyap#ifndef tw_osl_vsprintf
486152213Svkashyap/* Standard vsprintf. */
487152213Svkashyapextern TW_INT32	tw_osl_vsprintf(TW_INT8 *dest, const TW_INT8 *fmt, va_list ap);
488152213Svkashyap#endif
489152213Svkashyap
490152213Svkashyap
491144966Svkashyap#ifdef TW_OSL_CAN_SLEEP
492144966Svkashyap#ifndef tw_osl_wakeup
493144966Svkashyap/* Wake up a thread sleeping by a call to tw_osl_sleep. */
494144966Svkashyapextern TW_VOID	tw_osl_wakeup(struct tw_cl_ctlr_handle *ctlr_handle,
495144966Svkashyap	TW_SLEEP_HANDLE *sleep_handle);
496144966Svkashyap#endif
497144966Svkashyap#endif /* TW_OSL_CAN_SLEEP */
498144966Svkashyap
499144966Svkashyap
500144966Svkashyap#ifdef TW_OSL_PCI_CONFIG_ACCESSIBLE
501144966Svkashyap#ifndef tw_osl_write_pci_config
502144966Svkashyap/* Write 'value' of 'size' bytes at 'offset' in the PCI config space. */
503144966Svkashyapextern TW_VOID	tw_osl_write_pci_config(struct tw_cl_ctlr_handle *ctlr_handle,
504144966Svkashyap	TW_INT32 offset, TW_INT32 value, TW_INT32 size);
505144966Svkashyap#endif
506144966Svkashyap#endif /* TW_OSL_PCI_CONFIG_ACCESSIBLE */
507144966Svkashyap
508144966Svkashyap
509144966Svkashyap#ifndef tw_osl_write_reg
510144966Svkashyap/*
511144966Svkashyap * Write 'value' of 'size' (max 4) bytes at 'offset' from base address of
512144966Svkashyap * this controller.
513144966Svkashyap */
514144966Svkashyapextern TW_VOID	tw_osl_write_reg(struct tw_cl_ctlr_handle *ctlr_handle,
515144966Svkashyap	TW_INT32 offset, TW_INT32 value, TW_INT32 size);
516144966Svkashyap#endif
517144966Svkashyap
518144966Svkashyap
519144966Svkashyap
520144966Svkashyap/* Functions in the Common Layer */
521144966Svkashyap
522144966Svkashyap/* Creates and queues AEN's.  Also notifies OS Layer. */
523144966Svkashyapextern TW_VOID tw_cl_create_event(struct tw_cl_ctlr_handle *ctlr_handle,
524144966Svkashyap	TW_UINT8 queue_event, TW_UINT8 event_src, TW_UINT16 event_code,
525144966Svkashyap	TW_UINT8 severity, TW_UINT8 *severity_str, TW_UINT8 *event_desc,
526144966Svkashyap	TW_UINT8 *event_specific_desc, ...);
527144966Svkashyap
528144966Svkashyap/* Indicates whether a ctlr is supported by CL. */
529144966Svkashyapextern TW_INT32	tw_cl_ctlr_supported(TW_INT32 vendor_id, TW_INT32 device_id);
530144966Svkashyap
531144966Svkashyap
532144966Svkashyap/* Submit a firmware cmd packet. */
533144966Svkashyapextern TW_INT32	tw_cl_fw_passthru(struct tw_cl_ctlr_handle *ctlr_handle,
534144966Svkashyap	struct tw_cl_req_packet *req_pkt, struct tw_cl_req_handle *req_handle);
535144966Svkashyap
536144966Svkashyap
537144966Svkashyap/* Find out how much memory CL needs. */
538144966Svkashyapextern TW_INT32	tw_cl_get_mem_requirements(
539144966Svkashyap	struct tw_cl_ctlr_handle *ctlr_handle, TW_UINT32 flags,
540152213Svkashyap	TW_INT32 device_id, TW_INT32 max_simult_reqs, TW_INT32 max_aens,
541144966Svkashyap	TW_UINT32 *alignment, TW_UINT32 *sg_size_factor,
542144966Svkashyap	TW_UINT32 *non_dma_mem_size, TW_UINT32 *dma_mem_size
543144966Svkashyap	);
544144966Svkashyap
545144966Svkashyap
546152213Svkashyap/* Return PCI BAR info. */
547152213Svkashyapextern TW_INT32 tw_cl_get_pci_bar_info(TW_INT32 device_id, TW_INT32 bar_type,
548152213Svkashyap	TW_INT32 *bar_num, TW_INT32 *bar0_offset, TW_INT32 *bar_size);
549152213Svkashyap
550152213Svkashyap
551144966Svkashyap/* Initialize Common Layer for a given controller. */
552144966Svkashyapextern TW_INT32	tw_cl_init_ctlr(struct tw_cl_ctlr_handle *ctlr_handle,
553152213Svkashyap	TW_UINT32 flags, TW_INT32 device_id, TW_INT32 max_simult_reqs,
554152213Svkashyap	TW_INT32 max_aens, TW_VOID *non_dma_mem, TW_VOID *dma_mem,
555152213Svkashyap	TW_UINT64 dma_mem_phys
556144966Svkashyap	);
557144966Svkashyap
558144966Svkashyap
559212008Sdelphijextern TW_VOID  tw_cl_set_reset_needed(struct tw_cl_ctlr_handle *ctlr_handle);
560212008Sdelphijextern TW_INT32 tw_cl_is_reset_needed(struct tw_cl_ctlr_handle *ctlr_handle);
561212008Sdelphijextern TW_INT32 tw_cl_is_active(struct tw_cl_ctlr_handle *ctlr_handle);
562212008Sdelphij
563144966Svkashyap/* CL's interrupt handler. */
564144966Svkashyapextern TW_INT32	tw_cl_interrupt(struct tw_cl_ctlr_handle *ctlr_handle);
565144966Svkashyap
566144966Svkashyap
567144966Svkashyap/* CL's ioctl handler. */
568144966Svkashyapextern TW_INT32	tw_cl_ioctl(struct tw_cl_ctlr_handle *ctlr_handle,
569197409Srdivacky	u_long cmd, TW_VOID *buf);
570144966Svkashyap
571144966Svkashyap
572144966Svkashyap#ifdef TW_OSL_DEBUG
573144966Svkashyap/* Print CL's state/statistics for a controller. */
574144966Svkashyapextern TW_VOID	tw_cl_print_ctlr_stats(struct tw_cl_ctlr_handle *ctlr_handle);
575144966Svkashyap
576144966Svkashyap/* Prints CL internal details of a given request. */
577144966Svkashyapextern TW_VOID	tw_cl_print_req_info(struct tw_cl_req_handle *req_handle);
578144966Svkashyap#endif /* TW_OSL_DEBUG */
579144966Svkashyap
580144966Svkashyap
581144966Svkashyap/* Soft reset controller. */
582144966Svkashyapextern TW_INT32	tw_cl_reset_ctlr(struct tw_cl_ctlr_handle *ctlr_handle);
583144966Svkashyap
584144966Svkashyap
585144966Svkashyap#ifdef TW_OSL_DEBUG
586144966Svkashyap/* Reset CL's statistics for a controller. */
587144966Svkashyapextern TW_VOID	tw_cl_reset_stats(struct tw_cl_ctlr_handle *ctlr_handle);
588144966Svkashyap#endif /* TW_OSL_DEBUG */
589144966Svkashyap
590144966Svkashyap
591144966Svkashyap/* Stop a controller. */
592144966Svkashyapextern TW_INT32	tw_cl_shutdown_ctlr(struct tw_cl_ctlr_handle *ctlr_handle,
593144966Svkashyap	TW_UINT32 flags);
594144966Svkashyap
595144966Svkashyap
596144966Svkashyap/* Submit a SCSI I/O request. */
597144966Svkashyapextern TW_INT32	tw_cl_start_io(struct tw_cl_ctlr_handle *ctlr_handle,
598144966Svkashyap	struct tw_cl_req_packet *req_pkt, struct tw_cl_req_handle *req_handle);
599144966Svkashyap
600144966Svkashyap
601152213Svkashyap#endif /* TW_BUILDING_API */
602152213Svkashyap
603144966Svkashyap#endif /* TW_CL_SHARE_H */
604