xref: /freebsd/sys/dev/hptmv/raid5n.h (revision 734e82fe33aa764367791a7d603b383996c6b40b)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2004-2005 HighPoint Technologies, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 #ifdef _RAID5N_
29 
30 /* OS provided function, call only at initialization time */
31 extern void * HPTLIBAPI os_alloc_page(_VBUS_ARG0);      /* may be cached memory */
32 extern void * HPTLIBAPI os_alloc_dma_page(_VBUS_ARG0);  /* must be non-cached memory */
33 /* implement if the driver can be unloaded */
34 void HPTLIBAPI os_free_page(_VBUS_ARG void *p);
35 void HPTLIBAPI os_free_dma_page(_VBUS_ARG void *p);
36 
37 typedef void (* HPTLIBAPI xfer_done_fn)(_VBUS_ARG void *tag, int result);
38 
39 
40 #define DATAXFER_STACK_VAR
41 #define DATAXFER_INIT_ARG 0
42 
43 #define dataxfer_init(arg) 0
44 #define dataxfer_add_item(handle, host, cache, bytes, tocache) \
45 		if (tocache) memcpy((PUCHAR)(cache), (PUCHAR)(host), bytes); \
46 		else memcpy((PUCHAR)(host), (PUCHAR)(cache), bytes)
47 #define dataxfer_exec(handle, done, tag) done(_VBUS_P tag, 0)
48 #define dataxfer_poll()
49 
50 
51 typedef void (* HPTLIBAPI xor_done_fn)(_VBUS_ARG void *tag, int result);
52 
53 
54 #define XOR_STACK_VAR
55 #define XOR_INIT_ARG 0
56 
57 /* DoXor1, DoXor2 provided by platform dependent code */
58 void HPTLIBAPI DoXor1(ULONG *p0, ULONG *p1, ULONG *p2, UINT nBytes);
59 void HPTLIBAPI DoXor2(ULONG *p0, ULONG *p2, UINT nBytes);
60 #define max_xor_way 2
61 #define xor_init(arg) 0
62 #define xor_add_item(handle, dest, src, nsrc, bytes) \
63 	do {\
64 		if (((void**)(src))[0]==dest)\
65 			DoXor2((PULONG)(dest), ((PULONG *)(src))[1], bytes);\
66 		else\
67 			DoXor1((PULONG)(dest), ((PULONG *)(src))[0], ((PULONG *)(src))[1], bytes);\
68 	} while(0)
69 #define xor_exec(handle, done, tag) done(_VBUS_P tag, 0)
70 #define xor_poll()
71 
72 
73 /* set before calling init_raid5_memory */
74 extern UINT num_raid5_pages;
75 
76 /* called by init.c */
77 extern void HPTLIBAPI init_raid5_memory(_VBUS_ARG0);
78 extern void HPTLIBAPI free_raid5_memory(_VBUS_ARG0);
79 
80 /* asynchronous flush, may be called periodly */
81 extern void HPTLIBAPI flush_stripe_cache(_VBUS_ARG0);
82 extern void HPTLIBAPI flush_raid5_async(PVDevice pArray, DPC_PROC done, void *arg);
83 
84 /* synchronous function called at shutdown */
85 extern int HPTLIBAPI flush_raid5(PVDevice pArray);
86 
87 extern void HPTLIBAPI raid5_free(_VBUS_ARG PVDevice pArray);
88 
89 struct free_heap_block {
90 	struct free_heap_block *next;
91 };
92 
93 #ifndef LIST_H_INCLUDED
94 struct list_head {
95 	struct list_head *next, *prev;
96 };
97 #endif
98 
99 struct free_page {
100 	struct free_page *link;
101 };
102 
103 struct r5_global_data {
104 	int enable_write_back;
105 	struct list_head inactive_list;
106 	struct list_head dirty_list;
107 	struct list_head active_list;
108 #ifdef R5_CONTIG_CACHE
109 	BUS_ADDR page_base_phys;
110 	PUCHAR page_base_virt;
111 	PUCHAR page_current;
112 #endif
113 	struct free_heap_block *free_heap_slots[10];
114 	struct free_page *free_pages;
115 	UINT num_free_pages;
116 	UINT active_stripes;
117 	UINT num_flushing;
118 	PCommand cache_wait_list;
119 
120 	LBA_T __start[MAX_MEMBERS];
121 	USHORT __sectors[MAX_MEMBERS];
122 };
123 
124 
125 #endif
126