1174604Sscottl/*
2174604Sscottl * Copyright (c) HighPoint Technologies, Inc.
3174604Sscottl * All rights reserved.
4174604Sscottl *
5174604Sscottl * Redistribution and use in source and binary forms, with or without
6174604Sscottl * modification, are permitted provided that the following conditions
7174604Sscottl * are met:
8174604Sscottl * 1. Redistributions of source code must retain the above copyright
9174604Sscottl *    notice, this list of conditions and the following disclaimer.
10174604Sscottl * 2. Redistributions in binary form must reproduce the above copyright
11174604Sscottl *    notice, this list of conditions and the following disclaimer in the
12174604Sscottl *    documentation and/or other materials provided with the distribution.
13174604Sscottl *
14174604Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15174604Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16174604Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17174604Sscottl * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18174604Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19174604Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20174604Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21174604Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22174604Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23174604Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24174604Sscottl * SUCH DAMAGE.
25174604Sscottl *
26174604Sscottl * $FreeBSD$
27174604Sscottl */
28174604Sscottl#include <dev/hptrr/hptrr_config.h>
29174604Sscottl/*
30176018Sscottl * $Id: ldm.h,v 1.69 2007/11/22 07:31:55 gmm Exp $
31174604Sscottl * Copyright (C) 2004-2005 HighPoint Technologies, Inc. All rights reserved.
32174604Sscottl */
33174604Sscottl#ifndef _HPT_LDM_H_
34174604Sscottl#define _HPT_LDM_H_
35174604Sscottl
36176018Sscottl#define VERMAGIC_LDM 69
37174604Sscottl
38174604Sscottl#if defined(__cplusplus)
39174604Sscottlextern "C" {
40174604Sscottl#endif
41174604Sscottl
42174604Sscottl
43174604Sscottl#define __hpt_set_ver(x, v1, v2, v3, v4, v5) x ## _R_ ## v1 ## _ ## v2 ## _ ## v3 ## _ ## v4 ## _ ## v5
44174604Sscottl#define _hpt_set_ver(x, v1, v2, v3, v4, v5)  __hpt_set_ver(x, v1, v2, v3, v4, v5)
45174604Sscottl#define hpt_set_ver(x)               _hpt_set_ver(x, VERMAGIC_OSM, VERMAGIC_HIM, VERMAGIC_LDM, VERMAGIC_ARRAY, MAX_MEMBERS)
46174604Sscottl
47174604Sscottl#define ldm_register_him        hpt_set_ver(ldm_register_him)
48174604Sscottl#define ldm_register_vdev_class hpt_set_ver(ldm_register_vdev_class)
49174604Sscottl#define ldm_alloc_cmds          hpt_set_ver(ldm_alloc_cmds)
50174604Sscottl
51174604Sscottl
52174604Sscottl#ifndef HPT_INTERFACE_VERSION
53174604Sscottl#define HPT_INTERFACE_VERSION 0x02000001
54174604Sscottl#endif
55174604Sscottl
56174604Sscottl#define MAX_PARTITIONS_PER_DISK	4
57174604Sscottl#if defined(__MAX_PARTITIONS_PER_DISK) && MAX_PARTITIONS_PER_DISK > __MAX_PARTITIONS_PER_DISK
58174604Sscottl#error "Please redefine MAX_PARTITIONS_PER_DISK!!!"
59174604Sscottl#endif
60174604Sscottl
61174604Sscottl#define MAX(a,b) (((a)>(b))?(a):(b))
62174604Sscottl#define MIN(a,b) (((a)<(b))?(a):(b))
63174604Sscottl
64174604Sscottl
65176018Sscottltypedef char check_HPT_TIME_is_unsigned[ (HPT_TIME)(-1) > 0 ? 1 : -1 ];
66176018Sscottl
67176018Sscottl#define hpt_time_after_eq(a, b) ((long)(a) - (long)(b) >= 0)
68176018Sscottl#define hpt_time_after(a, b) ((long)(a) - (long)(b) > 0)
69176018Sscottl
70176018Sscottl
71176018Sscottl
72174604Sscottlstruct freelist {
73174604Sscottl	int dma;
74174604Sscottl	HPT_UINT alignment;
75174604Sscottl	HPT_UINT count;
76174604Sscottl	HPT_UINT size;
77174604Sscottl	void * head;
78174604Sscottl	struct freelist *next;
79176939Sscottl#if DBG
80174604Sscottl	char *tag;
81174604Sscottl	HPT_UINT reserved_count;
82174604Sscottl	#define freelist_debug_tag(list, _tag) (list)->tag = _tag
83174604Sscottl#else
84174604Sscottl	#define freelist_debug_tag(list, _tag)
85174604Sscottl#endif
86174604Sscottl};
87174604Sscottl
88174604Sscottl
89174604Sscottlvoid freelist_reserve(struct freelist *list, void *osext, HPT_UINT size, HPT_UINT count);
90174604Sscottl
91174604Sscottlvoid *freelist_get(struct freelist *);
92174604Sscottlvoid freelist_put(struct freelist *, void *p);
93174604Sscottl
94174604Sscottlvoid freelist_reserve_dma(struct freelist *list, void *osext, HPT_UINT size, HPT_UINT alignment, HPT_UINT count);
95174604Sscottlvoid *freelist_get_dma(struct freelist *, BUS_ADDRESS *busaddr);
96174604Sscottlvoid freelist_put_dma(struct freelist *, void *p, BUS_ADDRESS busaddr);
97174604Sscottl
98174604Sscottl
99174604Sscottl#define freelist_reserve_with_tag(list, osext, size, count) \
100174604Sscottl	do {\
101174604Sscottl		freelist_debug_tag(list, #list  " at " __FILE__);\
102174604Sscottl		freelist_reserve(list, osext, size, count);\
103174604Sscottl	}while(0)
104174604Sscottl
105174604Sscottl#define freelist_reserve_dma_with_tag(list, osext, size, alignment, count) \
106174604Sscottl	do {\
107174604Sscottl		freelist_debug_tag(list, #list " at " __FILE__);\
108174604Sscottl		freelist_reserve_dma(list, osext, size, alignment, count);\
109174604Sscottl	}while(0)
110174604Sscottl
111174604Sscottlstruct lock_request {
112174604Sscottl	HPT_U64 start, end;
113174604Sscottl	struct lock_request *next;
114174604Sscottl	struct list_head waiters; /* blocked commands */
115174604Sscottl	struct tq_item callback;
116176018Sscottl	int lock_cc;
117174604Sscottl};
118174604Sscottl
119176018Sscottl#define INIT_LOCK_REQUEST(req, _start, _end, _cb, _arg, _cc) \
120174604Sscottl	do {\
121174604Sscottl		(req)->next = 0;\
122174604Sscottl		(req)->start = _start;\
123174604Sscottl		(req)->end = _end;\
124174604Sscottl		INIT_TQ_ITEM(&(req)->callback, _cb, _arg);\
125174604Sscottl		INIT_LIST_HEAD(&(req)->waiters);\
126176018Sscottl		(req)->lock_cc = _cc;\
127174604Sscottl	} while (0)
128174604Sscottl
129174604Sscottlstruct task_queue {
130174604Sscottl	struct tq_item *head, *tail;
131174604Sscottl};
132174604Sscottl
133174604Sscottl#define TQ_EMPTY(tq) ((tq)->head==0)
134174604Sscottl
135174604Sscottlstruct dmapool_order {
136174604Sscottl	HPT_UINT npages;
137174604Sscottl	struct tq_item wakeup_fn;
138174604Sscottl	struct dmapool_order *next;
139174604Sscottl};
140174604Sscottl
141174604Sscottlstruct dmapool_client {
142174604Sscottl	void * handle;
143174604Sscottl	HPT_UINT (*shrink)(void *handle, HPT_UINT npages);
144176018Sscottl	int (*resume)(void *handle);
145174604Sscottl	struct dmapool_client *next;
146174604Sscottl};
147174604Sscottl
148174604Sscottltypedef struct _VBUS * PVBUS;
149174604Sscottltypedef struct _VDEV * PVDEV;
150174604Sscottl
151174604Sscottl
152174604Sscottlvoid dmapool_register_client(PVBUS vbus, struct dmapool_client *client);
153174604Sscottl
154174604Sscottl
155174604Sscottlvoid dmapool_active(PVBUS vbus);
156174604Sscottl
157174604Sscottl/* return 0 if the request is immediately satisfied, non-zero otherwise. */
158174604Sscottlint dmapool_make_order(PVBUS vbus, struct dmapool_order *order);
159174604Sscottl
160174604Sscottl
161174604Sscottlvoid *dmapool_get_page(PVBUS vbus, BUS_ADDRESS *busaddr);
162174604Sscottlvoid *dmapool_get_page_at(PVBUS vbus, void *p, BUS_ADDRESS *busaddr);
163174604Sscottlvoid dmapool_put_page(PVBUS vbus, void *p, BUS_ADDRESS busaddr);
164174604Sscottlvoid dmapool_init(PVBUS vbus);
165174604SscottlHPT_UINT dmapool_max_class_pages(PVBUS vbus);
166174604Sscottl
167174604Sscottl
168174604Sscottlstruct timer_call {
169174604Sscottl	HPT_U32 interval; /*microseconds*/
170174604Sscottl	HPT_TIME expire_time; /*microseconds*/
171174604Sscottl	void (*proc)(void * arg);
172174604Sscottl	void * arg;
173174604Sscottl	struct timer_call ** pprev;
174174604Sscottl	struct timer_call * next;
175174604Sscottl};
176174604Sscottl
177174604Sscottl#define ldm_init_timer(timer) do { (timer)->next=0; (timer)->pprev=0; } while (0)
178174604Sscottl
179174604Sscottl#define INIT_TIMER_CALL(timer, _interval, _proc, _arg) \
180174604Sscottl	do { \
181174604Sscottl		HPT_ASSERT((timer)->next==0 && (timer)->pprev==0);\
182174604Sscottl		(timer)->interval = _interval;\
183174604Sscottl		(timer)->proc = _proc;\
184174604Sscottl		(timer)->arg = _arg;\
185174604Sscottl	} while(0)
186174604Sscottl
187174604Sscottlvoid ldm_request_timer(PVBUS vbus, struct timer_call * tc);
188174604Sscottlvoid ldm_remove_timer(PVBUS vbus, struct timer_call * tc);
189174604Sscottlvoid ldm_on_timer(PVBUS vbus);
190174604Sscottl
191174604Sscottl
192174604Sscottltypedef struct _LDM_ADAPTER
193174604Sscottl{
194174604Sscottl	struct _LDM_ADAPTER *next;
195174604Sscottl	HIM  *him;
196174604Sscottl	void *him_handle;
197174604Sscottl	PVBUS vbus;
198174604Sscottl	struct freelist freelist_dev;
199174604Sscottl	struct freelist freelist_plugged_dpc;
200174604Sscottl	HPT_BOOL master;
201174604Sscottl}
202174604SscottlLDM_ADAPTER, *PLDM_ADAPTER;
203174604Sscottl
204174604Sscottltypedef struct _IOCTL_ARG
205174604Sscottl{
206174604Sscottl	struct list_head link;
207174604Sscottl	PVBUS vbus;
208174604Sscottl	HPT_U32 dwIoControlCode;
209174604Sscottl	HPT_U32 nInBufferSize;
210174604Sscottl	HPT_U32 nOutBufferSize;
211174604Sscottl	void *  lpInBuffer;
212174604Sscottl	void *  lpOutBuffer;
213174604Sscottl	HPT_U32 *lpBytesReturned;
214174604Sscottl	void *  ioctl_cmnd;
215174604Sscottl	void (* done)(struct _IOCTL_ARG *);
216174604Sscottl	int     result; /* HPT_IOCTL_RESULT_ */
217174604Sscottl	struct tq_item dpc;
218174604Sscottl} IOCTL_ARG;
219174604Sscottl
220174604Sscottl#define HPT_IOCTL_RESULT_OK          0
221174604Sscottl#define HPT_IOCTL_RESULT_FAILED     (-1)
222174604Sscottl#define HPT_IOCTL_RESULT_INVALID    (-2)
223174604Sscottl#define HPT_IOCTL_RESULT_RETRY      (-3)
224174604Sscottl#define HPT_IOCTL_RESULT_WRONG_VBUS (-4)
225174604Sscottl
226174604Sscottlvoid ldm_ioctl(	PVBUS vbus,	IOCTL_ARG *IAPnt);
227174604SscottlHPT_U32 ldm_get_device_id(PVDEV vd); /* for ioctl */
228174604Sscottlvoid ldm_set_rebuild_priority(PVBUS vbus, int priority);
229174604Sscottlvoid ldm_set_autorebuild(PVBUS vbus, int enable);
230176018Sscottlvoid ldm_set_spindown_disks_timeout(PVBUS vbus, HPT_U8 timeout);
231174604Sscottl
232176018Sscottl#ifndef __HPT_RAW_LBA
233176018Sscottl#define __HPT_RAW_LBA HPT_RAW_LBA
234176018Sscottl#endif
235176018Sscottl
236174604Sscottl#include <dev/hptrr/array.h>
237174604Sscottl
238174604Sscottltypedef struct hpt_raw_disk
239174604Sscottl{
240174604Sscottl#ifdef SUPPORT_ARRAY
241174604Sscottl	PRAW_PARTITION raw_part_list;
242176018Sscottl	__HPT_RAW_LBA max_available_capacity;
243176018Sscottl	__HPT_RAW_LBA total_available_capacity;
244174604Sscottl#endif
245176018Sscottl	__HPT_RAW_LBA real_capacity;
246176018Sscottl	__HPT_RAW_LBA head_position;
247174604Sscottl
248174604Sscottl	HPT_U16 max_sectors_per_cmd;
249176018Sscottl	HPT_U8  max_queue_depth;
250174604Sscottl	HPT_U8  user_select_mode;
251174604Sscottl
252176018Sscottl	HPT_UINT  uninitialized : 1;
253176018Sscottl	HPT_UINT  legacy_disk : 1;
254176018Sscottl	HPT_UINT  is_spare : 1;
255176018Sscottl	HPT_UINT  v3_format : 1;
256176018Sscottl	HPT_UINT  need_sync : 1;
257176018Sscottl	HPT_UINT  temp_spare : 1;
258176018Sscottl	HPT_UINT  need_check_array : 1;
259176018Sscottl	HPT_UINT  df_user_mode_set: 1;
260174604Sscottl
261176018Sscottl	HPT_UINT  df_read_ahead_set: 1;
262176018Sscottl	HPT_UINT  enable_read_ahead : 1;
263176018Sscottl	HPT_UINT  df_write_cache_set: 1;
264176018Sscottl	HPT_UINT  enable_write_cache : 1;
265176018Sscottl	HPT_UINT  df_tcq_set: 1;
266176018Sscottl	HPT_UINT  enable_tcq : 1;
267176018Sscottl	HPT_UINT  df_ncq_set: 1;
268176018Sscottl	HPT_UINT  enable_ncq : 1;
269174604Sscottl
270174604Sscottl	HIM  *				him;
271174604Sscottl	int 				index;
272174604Sscottl	PLDM_ADAPTER		adapter;
273174604Sscottl	void *				phy_dev;
274174604Sscottl	PIDENTIFY_DATA2		identify_data;
275174604Sscottl	char    model[40];
276174604Sscottl
277174604Sscottl	struct tq_item reset_dpc;
278174604Sscottl	int reset_pending;
279174604Sscottl
280174604Sscottl	struct tq_item fail_dpc;
281174604Sscottl	int fail_pending;
282174604Sscottl}
283174604SscottlHPT_RAW_DISK, *PHPT_RAW_DISK;
284174604Sscottl
285174604Sscottlstruct vdev_class
286174604Sscottl{
287174604Sscottl	struct vdev_class *next;
288174604Sscottl
289176018Sscottl	HPT_U8   __type;
290174604Sscottl	HPT_U8   stripped;        /* RAID0,3,5,6 */
291174604Sscottl	HPT_U8   redundancy;      /* RAID1-1, RAID3/5-1, RAID6-2 */
292174604Sscottl	HPT_U8   must_init;       /* RAID3,5,6 */
293176018Sscottl	HPT_U8   docache;
294174604Sscottl
295174604Sscottl	HPT_UINT vbus_ext_size;
296174604Sscottl	HPT_UINT vbus_ext_offset; /* used by LDM */
297174604Sscottl	HPT_UINT dev_ext_size;
298174604Sscottl	HPT_UINT cmd_ext_size;
299174604Sscottl
300174604Sscottl
301174604Sscottl	void (*get_mem_info)(PVBUS vbus, void *osext, int phydev_count);
302174604Sscottl	void (*queue_cmd)(PCOMMAND cmd);
303174604Sscottl	void (*member_failed)(struct _VDEV * vd);
304174604Sscottl
305174604Sscottl
306174604Sscottl	void (*initialize)(PVBUS vbus);
307174604Sscottl	void (*release)(PVBUS vbus);
308174604Sscottl	int  (*add)(PVDEV vd);
309174604Sscottl	void (*remove)(PVDEV vd);
310174604Sscottl	void (*reset)(PVDEV vd);
311174604Sscottl	void (*sync_stamp)(PVDEV vd);
312176018Sscottl	int  (*support_type)(int type);
313174604Sscottl};
314174604Sscottl
315174604Sscottl
316174604Sscottl#define VDEV_CLASS_CONSTRUCTOR(type, prefix) { \
317174604Sscottl	0, \
318174604Sscottl	type, \
319174604Sscottl	prefix ## _stripped, \
320174604Sscottl	prefix ## _redundancy, \
321174604Sscottl	prefix ## _must_init, \
322176018Sscottl	0, \
323174604Sscottl	prefix ## _vbus_ext_size, \
324174604Sscottl	0, \
325174604Sscottl	prefix ## _dev_ext_size, \
326174604Sscottl	prefix ## _cmd_ext_size, \
327174604Sscottl	prefix ## _get_mem_info, \
328174604Sscottl	prefix ## _queue_cmd, \
329174604Sscottl	prefix ## _member_failed, \
330174604Sscottl	prefix ## _initialize, \
331174604Sscottl	prefix ## _release, \
332174604Sscottl	prefix ## _add, \
333174604Sscottl	prefix ## _remove, \
334174604Sscottl	prefix ## _reset, \
335174604Sscottl	prefix ## _sync_stamp, \
336176018Sscottl	0 \
337174604Sscottl}
338174604Sscottl
339174604Sscottl#define VD_RAW       1
340174604Sscottl#define VD_PARTITION 4
341174604Sscottl
342174604Sscottl#define mIsArray(vdev_type) ((vdev_type)>VD_PARTITION)
343174604Sscottl
344174604Sscottl#define VD_RAID0     5
345174604Sscottl#define VD_RAID1     6
346174604Sscottl#define VD_JBOD      7
347174604Sscottl#define VD_RAID5     8
348174604Sscottl#define VD_RAID6     9
349176018Sscottl#define VD_RAID3     10
350176018Sscottl#define VD_RAID4     11
351176018Sscottl#define VD_RAID1E    12
352174604Sscottl
353176018Sscottl#define MAX_VD_TYPE_ID  12
354174604Sscottl
355174604Sscottlstruct vdev_class *ldm_find_vdev_class(HPT_U8 type);
356174604Sscottl
357174604Sscottltypedef struct _VDEV {
358174604Sscottl	PVBUS vbus;
359176018Sscottl	struct vdev_class *Class;
360176018Sscottl	HPT_U8 type;
361174604Sscottl	PVDEV parent;
362174604Sscottl	void * ext;
363174604Sscottl	HPT_U64 capacity;
364174604Sscottl	int     target_id;
365174604Sscottl	HPT_UINT cmds_per_request;
366174604Sscottl
367174604Sscottl	union {
368174604Sscottl#ifdef SUPPORT_ARRAY
369174604Sscottl		HPT_ARRAY array;
370174604Sscottl		HPT_PARTITION partition;
371174604Sscottl#endif
372174604Sscottl		HPT_RAW_DISK raw;
373174604Sscottl	} u;
374174604Sscottl
375174604Sscottl	HPT_U8 vf_online : 1;
376174604Sscottl	HPT_U8 vf_bootmark : 1;
377174604Sscottl	HPT_U8 vf_bootable : 1;
378174604Sscottl	HPT_U8 vf_resetting: 1;
379174604Sscottl	HPT_U8 vf_quiesced: 1;
380176018Sscottl	HPT_U8 vf_clslock: 1;
381174604Sscottl
382174604Sscottl	HPT_U8 cache_policy; /* see CACHE_POLICY_* */
383174604Sscottl
384174604Sscottl	HPT_UINT cq_len;
385174604Sscottl	HPT_UINT cmds_sent;
386174604Sscottl
387174604Sscottl	struct list_head link;
388174604Sscottl	struct list_head cq_wait_send;
389174604Sscottl	struct list_head cq_sent;
390174604Sscottl
391174604Sscottl	int cq_priority;
392174604Sscottl	struct list_head cq_wait_lock;
393174604Sscottl	struct lock_request *locks_granted;
394174604Sscottl	struct lock_request *locks_wait;
395174604Sscottl	HPT_U32 ioctl_id;
396174604Sscottl	void * cc_ext;
397174604Sscottl}
398174604SscottlVDEV;
399174604Sscottl
400174604Sscottl#define CACHE_POLICY_NONE 0
401174604Sscottl#define CACHE_POLICY_WRITE_THROUGH 1
402174604Sscottl#define CACHE_POLICY_WRITE_BACK 2
403174604Sscottl
404174604Sscottl
405174604Sscottlextern HIM *him_list;
406174604Sscottl
407174604Sscottl
408174604Sscottlvoid ldm_register_him(PHIM him);
409174604Sscottl
410174604Sscottl
411174604Sscottlvoid ldm_register_vdev_class(struct vdev_class *Class);
412174604Sscottl
413174604Sscottl
414174604SscottlHPT_BOOL ldm_register_adapter(PLDM_ADAPTER adapter);
415174604Sscottl
416174604Sscottl
417174604Sscottlint init_config(void);
418174604Sscottl
419174604SscottlHPT_UINT ldm_get_vbus_size(void);
420174604Sscottl
421174604Sscottl
422174604Sscottlvoid ldm_create_vbus(PVBUS vbus, void *osext);
423174604Sscottl
424174604Sscottl
425174604Sscottlvoid ldm_get_mem_info(PVBUS vbus, void *osext);
426174604Sscottl
427174604Sscottl
428174604Sscottlvoid *ldm_get_vbus_ext(PVBUS vbus, struct vdev_class *Class);
429174604Sscottl
430174604Sscottl
431174604SscottlPVBUS ldm_get_next_vbus(PVBUS vbus, void **posext);
432174604Sscottl
433174604Sscottl#define ldm_for_each_vbus(vbus, vbus_ext) \
434174604Sscottl	for (vbus = ldm_get_next_vbus(0, (void **)(void *)&vbus_ext); vbus; \
435174604Sscottl		vbus = ldm_get_next_vbus(vbus, (void **)(void *)&vbus_ext))
436174604Sscottl
437174604Sscottl
438174604Sscottlvoid ldm_initialize_vbus_async(PVBUS vbus, PLDM_ADAPTER master_adapter, void (*done)(void *osext));
439174604Sscottl
440174604Sscottl/* ldm_initialize_vbus is deprecated since it will hold the CPU too long. */
441174604Sscottl#define ldm_initialize_vbus(vbus, adapter) ldm_initialize_vbus_async(vbus, adapter, 0)
442174604Sscottl
443174604Sscottl
444174604Sscottlvoid ldm_release_vbus(PVBUS vbus);
445174604Sscottl
446174604SscottlPVDEV ldm_create_vdev(PVBUS vbus, HPT_U8 type);
447174604Sscottlvoid ldm_release_vdev(PVDEV vd);
448174604Sscottl
449174604SscottlPVDEV ldm_find_target(PVBUS vbus, int id);
450174604SscottlPVDEV ldm_find_stamp(PVBUS vbus, HPT_U32 stamp, int seq);
451174604Sscottl
452174604Sscottl
453174604SscottlPCOMMAND ldm_alloc_cmds(PVBUS vbus, HPT_UINT cnt);
454174604Sscottlvoid ldm_free_cmds(PCOMMAND cmd);
455174604Sscottl
456174604SscottlHPT_UINT ldm_get_cmd_size(void);
457174604SscottlPCOMMAND ldm_alloc_cmds_from_list(PVBUS vbus, struct freelist *list, HPT_UINT cnt);
458174604Sscottlvoid ldm_free_cmds_to_list(struct freelist *list, PCOMMAND cmd);
459174604Sscottl
460174604Sscottl
461174604SscottlPCOMMAND __ldm_alloc_cmd(struct freelist *list);
462174604Sscottl
463174604Sscottl#ifdef OS_SUPPORT_TASK
464174604Sscottl#define CMD_SET_PRIORITY(cmd, pri) cmd->priority = (pri)
465174604Sscottl#else
466174604Sscottl#define CMD_SET_PRIORITY(cmd, pri)
467174604Sscottl#endif
468174604Sscottl
469176018Sscottl
470174604Sscottl#define CMD_GROUP_GET(grp, cmd) \
471174604Sscottl	do {\
472174604Sscottl		grp->grplist->count++;\
473174604Sscottl		cmd = __ldm_alloc_cmd(grp->grplist);\
474174604Sscottl		cmd->vbus = grp->vbus;\
475174604Sscottl		cmd->grplist = grp->grplist;\
476174604Sscottl		CMD_SET_PRIORITY(cmd, grp->priority);\
477174604Sscottl	} while(0)
478174604Sscottl
479174604Sscottl#define CMD_GROUP_PUT(grp, cmd) \
480174604Sscottl	do {\
481174604Sscottl		freelist_put(grp->grplist, cmd);\
482174604Sscottl		grp->grplist->count--;\
483174604Sscottl	} while (0)
484174604Sscottl
485174604Sscottl
486176018Sscottl
487176018Sscottl
488174604Sscottlvoid ldm_queue_cmd(PCOMMAND cmd);
489174604Sscottlvoid vdev_queue_cmd(PCOMMAND cmd);
490174604Sscottlvoid ldm_finish_cmd(PCOMMAND cmd);
491174604Sscottl
492174604Sscottl
493174604Sscottlint  ldm_acquire_lock(PVDEV vd, struct lock_request *req);
494174604Sscottlvoid ldm_release_lock(PVDEV vd, struct lock_request *req);
495174604Sscottl
496174604Sscottlvoid ldm_queue_task(struct task_queue *tq, struct tq_item *t);
497174604Sscottlvoid ldm_queue_vbus_dpc(PVBUS vbus, struct tq_item *t);
498174604Sscottl
499174604SscottlHPT_BOOL ldm_intr(PVBUS vbus);
500174604Sscottlvoid ldm_run(PVBUS vbus);
501174604Sscottlint ldm_idle(PVBUS vbus);
502174604Sscottl
503174604Sscottl
504174604Sscottlint ldm_reset_vbus(PVBUS vbus);
505174604Sscottl
506174604Sscottl
507174604Sscottlvoid ldm_suspend(PVBUS vbus);
508174604Sscottlvoid ldm_resume(PVBUS vbus);
509174604Sscottlvoid ldm_shutdown(PVBUS vbus);/*shutdown all the controllers*/
510174604Sscottl
511174604Sscottl
512174604Sscottl#define HIM_EVENT_DEVICE_REMOVED 1
513174604Sscottl#define HIM_EVENT_DEVICE_PLUGGED 2
514174604Sscottl#define HIM_EVENT_DEVICE_ERROR   3
515174604Sscottl#define HIM_EVENT_RESET_REQUIRED 4
516174604Sscottl#define HIM_EVENT_QUIESCE_DEVICE 5
517174604Sscottl#define HIM_EVENT_UNQUIESCE_DEVICE 6
518174604Sscottl#define HIM_EVENT_CONFIG_CHANGED 7
519174604Sscottl
520174604Sscottlvoid ldm_event_notify(HPT_U32 event, void *arg1, void *arg2);
521174604Sscottl
522174604Sscottlvoid log_sector_repair(PVDEV vd, int success, HPT_LBA lba, HPT_U16 nsectors);
523174604Sscottl
524174604Sscottlvoid ldm_register_device(PVDEV vd);
525174604Sscottlvoid ldm_unregister_device(PVDEV vd);
526174604Sscottl
527174604SscottlPVBUS him_handle_to_vbus(void * him_handle);
528176018Sscottlvoid ldm_ide_fixstring (HPT_U8 *s, const int bytecount);
529174604Sscottl#if defined(__cplusplus)
530174604Sscottl}
531174604Sscottl#endif
532174604Sscottl#endif
533