xref: /freebsd/sys/dev/hptrr/ldm.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1718cf2ccSPedro F. Giffuni /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
4b063a422SScott Long  * Copyright (c) HighPoint Technologies, Inc.
5b063a422SScott Long  * All rights reserved.
6b063a422SScott Long  *
7b063a422SScott Long  * Redistribution and use in source and binary forms, with or without
8b063a422SScott Long  * modification, are permitted provided that the following conditions
9b063a422SScott Long  * are met:
10b063a422SScott Long  * 1. Redistributions of source code must retain the above copyright
11b063a422SScott Long  *    notice, this list of conditions and the following disclaimer.
12b063a422SScott Long  * 2. Redistributions in binary form must reproduce the above copyright
13b063a422SScott Long  *    notice, this list of conditions and the following disclaimer in the
14b063a422SScott Long  *    documentation and/or other materials provided with the distribution.
15b063a422SScott Long  *
16b063a422SScott Long  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17b063a422SScott Long  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18b063a422SScott Long  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19b063a422SScott Long  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20b063a422SScott Long  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21b063a422SScott Long  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22b063a422SScott Long  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23b063a422SScott Long  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24b063a422SScott Long  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25b063a422SScott Long  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26b063a422SScott Long  * SUCH DAMAGE.
27b063a422SScott Long  */
28b063a422SScott Long #include <dev/hptrr/hptrr_config.h>
29b063a422SScott Long /*
304fdb276aSScott Long  * $Id: ldm.h,v 1.69 2007/11/22 07:31:55 gmm Exp $
31b063a422SScott Long  * Copyright (C) 2004-2005 HighPoint Technologies, Inc. All rights reserved.
32b063a422SScott Long  */
33b063a422SScott Long #ifndef _HPT_LDM_H_
34b063a422SScott Long #define _HPT_LDM_H_
35b063a422SScott Long 
364fdb276aSScott Long #define VERMAGIC_LDM 69
37b063a422SScott Long 
38b063a422SScott Long #if defined(__cplusplus)
39b063a422SScott Long extern "C" {
40b063a422SScott Long #endif
41b063a422SScott Long 
42b063a422SScott Long 
43b063a422SScott Long #define __hpt_set_ver(x, v1, v2, v3, v4, v5) x ## _R_ ## v1 ## _ ## v2 ## _ ## v3 ## _ ## v4 ## _ ## v5
44b063a422SScott Long #define _hpt_set_ver(x, v1, v2, v3, v4, v5)  __hpt_set_ver(x, v1, v2, v3, v4, v5)
45b063a422SScott Long #define hpt_set_ver(x)               _hpt_set_ver(x, VERMAGIC_OSM, VERMAGIC_HIM, VERMAGIC_LDM, VERMAGIC_ARRAY, MAX_MEMBERS)
46b063a422SScott Long 
47b063a422SScott Long #define ldm_register_him        hpt_set_ver(ldm_register_him)
48b063a422SScott Long #define ldm_register_vdev_class hpt_set_ver(ldm_register_vdev_class)
49b063a422SScott Long #define ldm_alloc_cmds          hpt_set_ver(ldm_alloc_cmds)
50b063a422SScott Long 
51b063a422SScott Long 
52b063a422SScott Long #ifndef HPT_INTERFACE_VERSION
53b063a422SScott Long #define HPT_INTERFACE_VERSION 0x02000001
54b063a422SScott Long #endif
55b063a422SScott Long 
56b063a422SScott Long #define MAX_PARTITIONS_PER_DISK	4
57b063a422SScott Long #if defined(__MAX_PARTITIONS_PER_DISK) && MAX_PARTITIONS_PER_DISK > __MAX_PARTITIONS_PER_DISK
58b063a422SScott Long #error "Please redefine MAX_PARTITIONS_PER_DISK!!!"
59b063a422SScott Long #endif
60b063a422SScott Long 
614fdb276aSScott Long typedef char check_HPT_TIME_is_unsigned[ (HPT_TIME)(-1) > 0 ? 1 : -1 ];
624fdb276aSScott Long 
634fdb276aSScott Long #define hpt_time_after_eq(a, b) ((long)(a) - (long)(b) >= 0)
644fdb276aSScott Long #define hpt_time_after(a, b) ((long)(a) - (long)(b) > 0)
654fdb276aSScott Long 
664fdb276aSScott Long 
674fdb276aSScott Long 
68b063a422SScott Long struct freelist {
69b063a422SScott Long 	int dma;
70b063a422SScott Long 	HPT_UINT alignment;
71b063a422SScott Long 	HPT_UINT count;
72b063a422SScott Long 	HPT_UINT size;
73b063a422SScott Long 	void * head;
74b063a422SScott Long 	struct freelist *next;
759d6a74ebSScott Long #if DBG
76b063a422SScott Long 	char *tag;
77b063a422SScott Long 	HPT_UINT reserved_count;
78b063a422SScott Long 	#define freelist_debug_tag(list, _tag) (list)->tag = _tag
79b063a422SScott Long #else
80b063a422SScott Long 	#define freelist_debug_tag(list, _tag)
81b063a422SScott Long #endif
82b063a422SScott Long };
83b063a422SScott Long 
84b063a422SScott Long 
85b063a422SScott Long void freelist_reserve(struct freelist *list, void *osext, HPT_UINT size, HPT_UINT count);
86b063a422SScott Long 
87b063a422SScott Long void *freelist_get(struct freelist *);
88b063a422SScott Long void freelist_put(struct freelist *, void *p);
89b063a422SScott Long 
90b063a422SScott Long void freelist_reserve_dma(struct freelist *list, void *osext, HPT_UINT size, HPT_UINT alignment, HPT_UINT count);
91b063a422SScott Long void *freelist_get_dma(struct freelist *, BUS_ADDRESS *busaddr);
92b063a422SScott Long void freelist_put_dma(struct freelist *, void *p, BUS_ADDRESS busaddr);
93b063a422SScott Long 
94b063a422SScott Long 
95b063a422SScott Long #define freelist_reserve_with_tag(list, osext, size, count) \
96b063a422SScott Long 	do {\
97b063a422SScott Long 		freelist_debug_tag(list, #list  " at " __FILE__);\
98b063a422SScott Long 		freelist_reserve(list, osext, size, count);\
99b063a422SScott Long 	}while(0)
100b063a422SScott Long 
101b063a422SScott Long #define freelist_reserve_dma_with_tag(list, osext, size, alignment, count) \
102b063a422SScott Long 	do {\
103b063a422SScott Long 		freelist_debug_tag(list, #list " at " __FILE__);\
104b063a422SScott Long 		freelist_reserve_dma(list, osext, size, alignment, count);\
105b063a422SScott Long 	}while(0)
106b063a422SScott Long 
107b063a422SScott Long struct lock_request {
108b063a422SScott Long 	HPT_U64 start, end;
109b063a422SScott Long 	struct lock_request *next;
110b063a422SScott Long 	struct list_head waiters; /* blocked commands */
111b063a422SScott Long 	struct tq_item callback;
1124fdb276aSScott Long 	int lock_cc;
113b063a422SScott Long };
114b063a422SScott Long 
1154fdb276aSScott Long #define INIT_LOCK_REQUEST(req, _start, _end, _cb, _arg, _cc) \
116b063a422SScott Long 	do {\
117b063a422SScott Long 		(req)->next = 0;\
118b063a422SScott Long 		(req)->start = _start;\
119b063a422SScott Long 		(req)->end = _end;\
120b063a422SScott Long 		INIT_TQ_ITEM(&(req)->callback, _cb, _arg);\
121b063a422SScott Long 		INIT_LIST_HEAD(&(req)->waiters);\
1224fdb276aSScott Long 		(req)->lock_cc = _cc;\
123b063a422SScott Long 	} while (0)
124b063a422SScott Long 
125b063a422SScott Long struct task_queue {
126b063a422SScott Long 	struct tq_item *head, *tail;
127b063a422SScott Long };
128b063a422SScott Long 
129b063a422SScott Long #define TQ_EMPTY(tq) ((tq)->head==0)
130b063a422SScott Long 
131b063a422SScott Long struct dmapool_order {
132b063a422SScott Long 	HPT_UINT npages;
133b063a422SScott Long 	struct tq_item wakeup_fn;
134b063a422SScott Long 	struct dmapool_order *next;
135b063a422SScott Long };
136b063a422SScott Long 
137b063a422SScott Long struct dmapool_client {
138b063a422SScott Long 	void * handle;
139b063a422SScott Long 	HPT_UINT (*shrink)(void *handle, HPT_UINT npages);
1404fdb276aSScott Long 	int (*resume)(void *handle);
141b063a422SScott Long 	struct dmapool_client *next;
142b063a422SScott Long };
143b063a422SScott Long 
144b063a422SScott Long typedef struct _VBUS * PVBUS;
145b063a422SScott Long typedef struct _VDEV * PVDEV;
146b063a422SScott Long 
147b063a422SScott Long 
148b063a422SScott Long void dmapool_register_client(PVBUS vbus, struct dmapool_client *client);
149b063a422SScott Long 
150b063a422SScott Long 
151b063a422SScott Long void dmapool_active(PVBUS vbus);
152b063a422SScott Long 
153b063a422SScott Long /* return 0 if the request is immediately satisfied, non-zero otherwise. */
154b063a422SScott Long int dmapool_make_order(PVBUS vbus, struct dmapool_order *order);
155b063a422SScott Long 
156b063a422SScott Long 
157b063a422SScott Long void *dmapool_get_page(PVBUS vbus, BUS_ADDRESS *busaddr);
158b063a422SScott Long void *dmapool_get_page_at(PVBUS vbus, void *p, BUS_ADDRESS *busaddr);
159b063a422SScott Long void dmapool_put_page(PVBUS vbus, void *p, BUS_ADDRESS busaddr);
160b063a422SScott Long void dmapool_init(PVBUS vbus);
161b063a422SScott Long HPT_UINT dmapool_max_class_pages(PVBUS vbus);
162b063a422SScott Long 
163b063a422SScott Long 
164b063a422SScott Long struct timer_call {
165b063a422SScott Long 	HPT_U32 interval; /*microseconds*/
166b063a422SScott Long 	HPT_TIME expire_time; /*microseconds*/
167b063a422SScott Long 	void (*proc)(void * arg);
168b063a422SScott Long 	void * arg;
169b063a422SScott Long 	struct timer_call ** pprev;
170b063a422SScott Long 	struct timer_call * next;
171b063a422SScott Long };
172b063a422SScott Long 
173b063a422SScott Long #define ldm_init_timer(timer) do { (timer)->next=0; (timer)->pprev=0; } while (0)
174b063a422SScott Long 
175b063a422SScott Long #define INIT_TIMER_CALL(timer, _interval, _proc, _arg) \
176b063a422SScott Long 	do { \
177b063a422SScott Long 		HPT_ASSERT((timer)->next==0 && (timer)->pprev==0);\
178b063a422SScott Long 		(timer)->interval = _interval;\
179b063a422SScott Long 		(timer)->proc = _proc;\
180b063a422SScott Long 		(timer)->arg = _arg;\
181b063a422SScott Long 	} while(0)
182b063a422SScott Long 
183b063a422SScott Long void ldm_request_timer(PVBUS vbus, struct timer_call * tc);
184b063a422SScott Long void ldm_remove_timer(PVBUS vbus, struct timer_call * tc);
185b063a422SScott Long void ldm_on_timer(PVBUS vbus);
186b063a422SScott Long 
187b063a422SScott Long 
188b063a422SScott Long typedef struct _LDM_ADAPTER
189b063a422SScott Long {
190b063a422SScott Long 	struct _LDM_ADAPTER *next;
191b063a422SScott Long 	HIM  *him;
192b063a422SScott Long 	void *him_handle;
193b063a422SScott Long 	PVBUS vbus;
194b063a422SScott Long 	struct freelist freelist_dev;
195b063a422SScott Long 	struct freelist freelist_plugged_dpc;
196b063a422SScott Long 	HPT_BOOL master;
197b063a422SScott Long }
198b063a422SScott Long LDM_ADAPTER, *PLDM_ADAPTER;
199b063a422SScott Long 
200b063a422SScott Long typedef struct _IOCTL_ARG
201b063a422SScott Long {
202b063a422SScott Long 	struct list_head link;
203b063a422SScott Long 	PVBUS vbus;
204b063a422SScott Long 	HPT_U32 dwIoControlCode;
205b063a422SScott Long 	HPT_U32 nInBufferSize;
206b063a422SScott Long 	HPT_U32 nOutBufferSize;
207b063a422SScott Long 	void *  lpInBuffer;
208b063a422SScott Long 	void *  lpOutBuffer;
209b063a422SScott Long 	HPT_U32 *lpBytesReturned;
210b063a422SScott Long 	void *  ioctl_cmnd;
211b063a422SScott Long 	void (* done)(struct _IOCTL_ARG *);
212b063a422SScott Long 	int     result; /* HPT_IOCTL_RESULT_ */
213b063a422SScott Long 	struct tq_item dpc;
214b063a422SScott Long } IOCTL_ARG;
215b063a422SScott Long 
216b063a422SScott Long #define HPT_IOCTL_RESULT_OK          0
217b063a422SScott Long #define HPT_IOCTL_RESULT_FAILED     (-1)
218b063a422SScott Long #define HPT_IOCTL_RESULT_INVALID    (-2)
219b063a422SScott Long #define HPT_IOCTL_RESULT_RETRY      (-3)
220b063a422SScott Long #define HPT_IOCTL_RESULT_WRONG_VBUS (-4)
221b063a422SScott Long 
222b063a422SScott Long void ldm_ioctl(	PVBUS vbus,	IOCTL_ARG *IAPnt);
223b063a422SScott Long HPT_U32 ldm_get_device_id(PVDEV vd); /* for ioctl */
224b063a422SScott Long void ldm_set_rebuild_priority(PVBUS vbus, int priority);
225b063a422SScott Long void ldm_set_autorebuild(PVBUS vbus, int enable);
2264fdb276aSScott Long void ldm_set_spindown_disks_timeout(PVBUS vbus, HPT_U8 timeout);
2274fdb276aSScott Long 
2284fdb276aSScott Long #ifndef __HPT_RAW_LBA
2294fdb276aSScott Long #define __HPT_RAW_LBA HPT_RAW_LBA
2304fdb276aSScott Long #endif
231b063a422SScott Long 
232b063a422SScott Long #include <dev/hptrr/array.h>
233b063a422SScott Long 
234b063a422SScott Long typedef struct hpt_raw_disk
235b063a422SScott Long {
236b063a422SScott Long #ifdef SUPPORT_ARRAY
237b063a422SScott Long 	PRAW_PARTITION raw_part_list;
2384fdb276aSScott Long 	__HPT_RAW_LBA max_available_capacity;
2394fdb276aSScott Long 	__HPT_RAW_LBA total_available_capacity;
240b063a422SScott Long #endif
2414fdb276aSScott Long 	__HPT_RAW_LBA real_capacity;
2424fdb276aSScott Long 	__HPT_RAW_LBA head_position;
243b063a422SScott Long 
244b063a422SScott Long 	HPT_U16 max_sectors_per_cmd;
2454fdb276aSScott Long 	HPT_U8  max_queue_depth;
246b063a422SScott Long 	HPT_U8  user_select_mode;
247b063a422SScott Long 
2484fdb276aSScott Long 	HPT_UINT  uninitialized : 1;
2494fdb276aSScott Long 	HPT_UINT  legacy_disk : 1;
2504fdb276aSScott Long 	HPT_UINT  is_spare : 1;
2514fdb276aSScott Long 	HPT_UINT  v3_format : 1;
2524fdb276aSScott Long 	HPT_UINT  need_sync : 1;
2534fdb276aSScott Long 	HPT_UINT  temp_spare : 1;
2544fdb276aSScott Long 	HPT_UINT  need_check_array : 1;
2554fdb276aSScott Long 	HPT_UINT  df_user_mode_set: 1;
256b063a422SScott Long 
2574fdb276aSScott Long 	HPT_UINT  df_read_ahead_set: 1;
2584fdb276aSScott Long 	HPT_UINT  enable_read_ahead : 1;
2594fdb276aSScott Long 	HPT_UINT  df_write_cache_set: 1;
2604fdb276aSScott Long 	HPT_UINT  enable_write_cache : 1;
2614fdb276aSScott Long 	HPT_UINT  df_tcq_set: 1;
2624fdb276aSScott Long 	HPT_UINT  enable_tcq : 1;
2634fdb276aSScott Long 	HPT_UINT  df_ncq_set: 1;
2644fdb276aSScott Long 	HPT_UINT  enable_ncq : 1;
265b063a422SScott Long 
266b063a422SScott Long 	HIM  *				him;
267b063a422SScott Long 	int 				index;
268b063a422SScott Long 	PLDM_ADAPTER		adapter;
269b063a422SScott Long 	void *				phy_dev;
270b063a422SScott Long 	PIDENTIFY_DATA2		identify_data;
271b063a422SScott Long 	char    model[40];
272b063a422SScott Long 
273b063a422SScott Long 	struct tq_item reset_dpc;
274b063a422SScott Long 	int reset_pending;
275b063a422SScott Long 
276b063a422SScott Long 	struct tq_item fail_dpc;
277b063a422SScott Long 	int fail_pending;
278b063a422SScott Long }
279b063a422SScott Long HPT_RAW_DISK, *PHPT_RAW_DISK;
280b063a422SScott Long 
281b063a422SScott Long struct vdev_class
282b063a422SScott Long {
283b063a422SScott Long 	struct vdev_class *next;
284b063a422SScott Long 
2854fdb276aSScott Long 	HPT_U8   __type;
286b063a422SScott Long 	HPT_U8   stripped;        /* RAID0,3,5,6 */
287b063a422SScott Long 	HPT_U8   redundancy;      /* RAID1-1, RAID3/5-1, RAID6-2 */
288b063a422SScott Long 	HPT_U8   must_init;       /* RAID3,5,6 */
2894fdb276aSScott Long 	HPT_U8   docache;
290b063a422SScott Long 
291b063a422SScott Long 	HPT_UINT vbus_ext_size;
292b063a422SScott Long 	HPT_UINT vbus_ext_offset; /* used by LDM */
293b063a422SScott Long 	HPT_UINT dev_ext_size;
294b063a422SScott Long 	HPT_UINT cmd_ext_size;
295b063a422SScott Long 
296b063a422SScott Long 
297b063a422SScott Long 	void (*get_mem_info)(PVBUS vbus, void *osext, int phydev_count);
298b063a422SScott Long 	void (*queue_cmd)(PCOMMAND cmd);
299b063a422SScott Long 	void (*member_failed)(struct _VDEV * vd);
300b063a422SScott Long 
301b063a422SScott Long 
302b063a422SScott Long 	void (*initialize)(PVBUS vbus);
303b063a422SScott Long 	void (*release)(PVBUS vbus);
304b063a422SScott Long 	int  (*add)(PVDEV vd);
305b063a422SScott Long 	void (*remove)(PVDEV vd);
306b063a422SScott Long 	void (*reset)(PVDEV vd);
307b063a422SScott Long 	void (*sync_stamp)(PVDEV vd);
3084fdb276aSScott Long 	int  (*support_type)(int type);
309b063a422SScott Long };
310b063a422SScott Long 
311b063a422SScott Long 
312b063a422SScott Long #define VDEV_CLASS_CONSTRUCTOR(type, prefix) { \
313b063a422SScott Long 	0, \
314b063a422SScott Long 	type, \
315b063a422SScott Long 	prefix ## _stripped, \
316b063a422SScott Long 	prefix ## _redundancy, \
317b063a422SScott Long 	prefix ## _must_init, \
3184fdb276aSScott Long 	0, \
319b063a422SScott Long 	prefix ## _vbus_ext_size, \
320b063a422SScott Long 	0, \
321b063a422SScott Long 	prefix ## _dev_ext_size, \
322b063a422SScott Long 	prefix ## _cmd_ext_size, \
323b063a422SScott Long 	prefix ## _get_mem_info, \
324b063a422SScott Long 	prefix ## _queue_cmd, \
325b063a422SScott Long 	prefix ## _member_failed, \
326b063a422SScott Long 	prefix ## _initialize, \
327b063a422SScott Long 	prefix ## _release, \
328b063a422SScott Long 	prefix ## _add, \
329b063a422SScott Long 	prefix ## _remove, \
330b063a422SScott Long 	prefix ## _reset, \
331b063a422SScott Long 	prefix ## _sync_stamp, \
3324fdb276aSScott Long 	0 \
333b063a422SScott Long }
334b063a422SScott Long 
335b063a422SScott Long #define VD_RAW       1
336b063a422SScott Long #define VD_PARTITION 4
337b063a422SScott Long 
338b063a422SScott Long #define mIsArray(vdev_type) ((vdev_type)>VD_PARTITION)
339b063a422SScott Long 
340b063a422SScott Long #define VD_RAID0     5
341b063a422SScott Long #define VD_RAID1     6
342b063a422SScott Long #define VD_JBOD      7
343b063a422SScott Long #define VD_RAID5     8
344b063a422SScott Long #define VD_RAID6     9
3454fdb276aSScott Long #define VD_RAID3     10
3464fdb276aSScott Long #define VD_RAID4     11
3474fdb276aSScott Long #define VD_RAID1E    12
348b063a422SScott Long 
3494fdb276aSScott Long #define MAX_VD_TYPE_ID  12
350b063a422SScott Long 
351b063a422SScott Long struct vdev_class *ldm_find_vdev_class(HPT_U8 type);
352b063a422SScott Long 
353b063a422SScott Long typedef struct _VDEV {
354b063a422SScott Long 	PVBUS vbus;
3554fdb276aSScott Long 	struct vdev_class *Class;
3564fdb276aSScott Long 	HPT_U8 type;
357b063a422SScott Long 	PVDEV parent;
358b063a422SScott Long 	void * ext;
359b063a422SScott Long 	HPT_U64 capacity;
360b063a422SScott Long 	int     target_id;
361b063a422SScott Long 	HPT_UINT cmds_per_request;
362b063a422SScott Long 
363b063a422SScott Long 	union {
364b063a422SScott Long #ifdef SUPPORT_ARRAY
365b063a422SScott Long 		HPT_ARRAY array;
366b063a422SScott Long 		HPT_PARTITION partition;
367b063a422SScott Long #endif
368b063a422SScott Long 		HPT_RAW_DISK raw;
369b063a422SScott Long 	} u;
370b063a422SScott Long 
371b063a422SScott Long 	HPT_U8 vf_online : 1;
372b063a422SScott Long 	HPT_U8 vf_bootmark : 1;
373b063a422SScott Long 	HPT_U8 vf_bootable : 1;
374b063a422SScott Long 	HPT_U8 vf_resetting: 1;
375b063a422SScott Long 	HPT_U8 vf_quiesced: 1;
3764fdb276aSScott Long 	HPT_U8 vf_clslock: 1;
377b063a422SScott Long 
378b063a422SScott Long 	HPT_U8 cache_policy; /* see CACHE_POLICY_* */
379b063a422SScott Long 
380b063a422SScott Long 	HPT_UINT cq_len;
381b063a422SScott Long 	HPT_UINT cmds_sent;
382b063a422SScott Long 
383b063a422SScott Long 	struct list_head link;
384b063a422SScott Long 	struct list_head cq_wait_send;
385b063a422SScott Long 	struct list_head cq_sent;
386b063a422SScott Long 
387b063a422SScott Long 	int cq_priority;
388b063a422SScott Long 	struct list_head cq_wait_lock;
389b063a422SScott Long 	struct lock_request *locks_granted;
390b063a422SScott Long 	struct lock_request *locks_wait;
391b063a422SScott Long 	HPT_U32 ioctl_id;
392b063a422SScott Long 	void * cc_ext;
393b063a422SScott Long }
394b063a422SScott Long VDEV;
395b063a422SScott Long 
396b063a422SScott Long #define CACHE_POLICY_NONE 0
397b063a422SScott Long #define CACHE_POLICY_WRITE_THROUGH 1
398b063a422SScott Long #define CACHE_POLICY_WRITE_BACK 2
399b063a422SScott Long 
400b063a422SScott Long 
401b063a422SScott Long extern HIM *him_list;
402b063a422SScott Long 
403b063a422SScott Long 
404b063a422SScott Long void ldm_register_him(PHIM him);
405b063a422SScott Long 
406b063a422SScott Long 
407b063a422SScott Long void ldm_register_vdev_class(struct vdev_class *Class);
408b063a422SScott Long 
409b063a422SScott Long 
410b063a422SScott Long HPT_BOOL ldm_register_adapter(PLDM_ADAPTER adapter);
411b063a422SScott Long 
412b063a422SScott Long 
413b063a422SScott Long int init_config(void);
414b063a422SScott Long 
415b063a422SScott Long HPT_UINT ldm_get_vbus_size(void);
416b063a422SScott Long 
417b063a422SScott Long 
418b063a422SScott Long void ldm_create_vbus(PVBUS vbus, void *osext);
419b063a422SScott Long 
420b063a422SScott Long 
421b063a422SScott Long void ldm_get_mem_info(PVBUS vbus, void *osext);
422b063a422SScott Long 
423b063a422SScott Long 
424b063a422SScott Long void *ldm_get_vbus_ext(PVBUS vbus, struct vdev_class *Class);
425b063a422SScott Long 
426b063a422SScott Long 
427b063a422SScott Long PVBUS ldm_get_next_vbus(PVBUS vbus, void **posext);
428b063a422SScott Long 
429b063a422SScott Long #define ldm_for_each_vbus(vbus, vbus_ext) \
430b063a422SScott Long 	for (vbus = ldm_get_next_vbus(0, (void **)(void *)&vbus_ext); vbus; \
431b063a422SScott Long 		vbus = ldm_get_next_vbus(vbus, (void **)(void *)&vbus_ext))
432b063a422SScott Long 
433b063a422SScott Long 
434b063a422SScott Long void ldm_initialize_vbus_async(PVBUS vbus, PLDM_ADAPTER master_adapter, void (*done)(void *osext));
435b063a422SScott Long 
436b063a422SScott Long /* ldm_initialize_vbus is deprecated since it will hold the CPU too long. */
437b063a422SScott Long #define ldm_initialize_vbus(vbus, adapter) ldm_initialize_vbus_async(vbus, adapter, 0)
438b063a422SScott Long 
439b063a422SScott Long 
440b063a422SScott Long void ldm_release_vbus(PVBUS vbus);
441b063a422SScott Long 
442b063a422SScott Long PVDEV ldm_create_vdev(PVBUS vbus, HPT_U8 type);
443b063a422SScott Long void ldm_release_vdev(PVDEV vd);
444b063a422SScott Long 
445b063a422SScott Long PVDEV ldm_find_target(PVBUS vbus, int id);
446b063a422SScott Long PVDEV ldm_find_stamp(PVBUS vbus, HPT_U32 stamp, int seq);
447b063a422SScott Long 
448b063a422SScott Long 
449b063a422SScott Long PCOMMAND ldm_alloc_cmds(PVBUS vbus, HPT_UINT cnt);
450b063a422SScott Long void ldm_free_cmds(PCOMMAND cmd);
451b063a422SScott Long 
452b063a422SScott Long HPT_UINT ldm_get_cmd_size(void);
453b063a422SScott Long PCOMMAND ldm_alloc_cmds_from_list(PVBUS vbus, struct freelist *list, HPT_UINT cnt);
454b063a422SScott Long void ldm_free_cmds_to_list(struct freelist *list, PCOMMAND cmd);
455b063a422SScott Long 
456b063a422SScott Long 
457b063a422SScott Long PCOMMAND __ldm_alloc_cmd(struct freelist *list);
458b063a422SScott Long 
459b063a422SScott Long #ifdef OS_SUPPORT_TASK
460b063a422SScott Long #define CMD_SET_PRIORITY(cmd, pri) cmd->priority = (pri)
461b063a422SScott Long #else
462b063a422SScott Long #define CMD_SET_PRIORITY(cmd, pri)
463b063a422SScott Long #endif
464b063a422SScott Long 
4654fdb276aSScott Long 
466b063a422SScott Long #define CMD_GROUP_GET(grp, cmd) \
467b063a422SScott Long 	do {\
468b063a422SScott Long 		grp->grplist->count++;\
469b063a422SScott Long 		cmd = __ldm_alloc_cmd(grp->grplist);\
470b063a422SScott Long 		cmd->vbus = grp->vbus;\
471b063a422SScott Long 		cmd->grplist = grp->grplist;\
472b063a422SScott Long 		CMD_SET_PRIORITY(cmd, grp->priority);\
473b063a422SScott Long 	} while(0)
474b063a422SScott Long 
475b063a422SScott Long #define CMD_GROUP_PUT(grp, cmd) \
476b063a422SScott Long 	do {\
477b063a422SScott Long 		freelist_put(grp->grplist, cmd);\
478b063a422SScott Long 		grp->grplist->count--;\
479b063a422SScott Long 	} while (0)
480b063a422SScott Long 
481b063a422SScott Long 
4824fdb276aSScott Long 
4834fdb276aSScott Long 
484b063a422SScott Long void ldm_queue_cmd(PCOMMAND cmd);
485b063a422SScott Long void vdev_queue_cmd(PCOMMAND cmd);
486b063a422SScott Long void ldm_finish_cmd(PCOMMAND cmd);
487b063a422SScott Long 
488b063a422SScott Long 
489b063a422SScott Long int  ldm_acquire_lock(PVDEV vd, struct lock_request *req);
490b063a422SScott Long void ldm_release_lock(PVDEV vd, struct lock_request *req);
491b063a422SScott Long 
492b063a422SScott Long void ldm_queue_task(struct task_queue *tq, struct tq_item *t);
493b063a422SScott Long void ldm_queue_vbus_dpc(PVBUS vbus, struct tq_item *t);
494b063a422SScott Long 
495b063a422SScott Long HPT_BOOL ldm_intr(PVBUS vbus);
496b063a422SScott Long void ldm_run(PVBUS vbus);
497b063a422SScott Long int ldm_idle(PVBUS vbus);
498b063a422SScott Long 
499b063a422SScott Long 
500b063a422SScott Long int ldm_reset_vbus(PVBUS vbus);
501b063a422SScott Long 
502b063a422SScott Long 
503b063a422SScott Long void ldm_suspend(PVBUS vbus);
504b063a422SScott Long void ldm_resume(PVBUS vbus);
505b063a422SScott Long void ldm_shutdown(PVBUS vbus);/*shutdown all the controllers*/
506b063a422SScott Long 
507b063a422SScott Long 
508b063a422SScott Long #define HIM_EVENT_DEVICE_REMOVED 1
509b063a422SScott Long #define HIM_EVENT_DEVICE_PLUGGED 2
510b063a422SScott Long #define HIM_EVENT_DEVICE_ERROR   3
511b063a422SScott Long #define HIM_EVENT_RESET_REQUIRED 4
512b063a422SScott Long #define HIM_EVENT_QUIESCE_DEVICE 5
513b063a422SScott Long #define HIM_EVENT_UNQUIESCE_DEVICE 6
514b063a422SScott Long #define HIM_EVENT_CONFIG_CHANGED 7
515b063a422SScott Long 
516b063a422SScott Long void ldm_event_notify(HPT_U32 event, void *arg1, void *arg2);
517b063a422SScott Long 
518b063a422SScott Long void log_sector_repair(PVDEV vd, int success, HPT_LBA lba, HPT_U16 nsectors);
519b063a422SScott Long 
520b063a422SScott Long void ldm_register_device(PVDEV vd);
521b063a422SScott Long void ldm_unregister_device(PVDEV vd);
522b063a422SScott Long 
523b063a422SScott Long PVBUS him_handle_to_vbus(void * him_handle);
5244fdb276aSScott Long void ldm_ide_fixstring (HPT_U8 *s, const int bytecount);
525b063a422SScott Long #if defined(__cplusplus)
526b063a422SScott Long }
527b063a422SScott Long #endif
528b063a422SScott Long #endif
529