xref: /freebsd/sys/dev/hptmv/raid5n.h (revision a0b9e2e854027e6ff61fb075a1309dbc71c42b54)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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  * $FreeBSD$
29  */
30 #ifdef _RAID5N_
31 
32 /* OS provided function, call only at initialization time */
33 extern void * HPTLIBAPI os_alloc_page(_VBUS_ARG0);      /* may be cached memory */
34 extern void * HPTLIBAPI os_alloc_dma_page(_VBUS_ARG0);  /* must be non-cached memory */
35 /* implement if the driver can be unloaded */
36 void HPTLIBAPI os_free_page(_VBUS_ARG void *p);
37 void HPTLIBAPI os_free_dma_page(_VBUS_ARG void *p);
38 
39 typedef void (* HPTLIBAPI xfer_done_fn)(_VBUS_ARG void *tag, int result);
40 
41 
42 #define DATAXFER_STACK_VAR
43 #define DATAXFER_INIT_ARG 0
44 
45 #define dataxfer_init(arg) 0
46 #define dataxfer_add_item(handle, host, cache, bytes, tocache) \
47 		if (tocache) memcpy((PUCHAR)(cache), (PUCHAR)(host), bytes); \
48 		else memcpy((PUCHAR)(host), (PUCHAR)(cache), bytes)
49 #define dataxfer_exec(handle, done, tag) done(_VBUS_P tag, 0)
50 #define dataxfer_poll()
51 
52 
53 typedef void (* HPTLIBAPI xor_done_fn)(_VBUS_ARG void *tag, int result);
54 
55 
56 #define XOR_STACK_VAR
57 #define XOR_INIT_ARG 0
58 
59 /* DoXor1, DoXor2 provided by platform dependent code */
60 void HPTLIBAPI DoXor1(ULONG *p0, ULONG *p1, ULONG *p2, UINT nBytes);
61 void HPTLIBAPI DoXor2(ULONG *p0, ULONG *p2, UINT nBytes);
62 #define max_xor_way 2
63 #define xor_init(arg) 0
64 #define xor_add_item(handle, dest, src, nsrc, bytes) \
65 	do {\
66 		if (((void**)(src))[0]==dest)\
67 			DoXor2((PULONG)(dest), ((PULONG *)(src))[1], bytes);\
68 		else\
69 			DoXor1((PULONG)(dest), ((PULONG *)(src))[0], ((PULONG *)(src))[1], bytes);\
70 	} while(0)
71 #define xor_exec(handle, done, tag) done(_VBUS_P tag, 0)
72 #define xor_poll()
73 
74 
75 /* set before calling init_raid5_memory */
76 extern UINT num_raid5_pages;
77 
78 /* called by init.c */
79 extern void HPTLIBAPI init_raid5_memory(_VBUS_ARG0);
80 extern void HPTLIBAPI free_raid5_memory(_VBUS_ARG0);
81 
82 /* asynchronous flush, may be called periodly */
83 extern void HPTLIBAPI flush_stripe_cache(_VBUS_ARG0);
84 extern void HPTLIBAPI flush_raid5_async(PVDevice pArray, DPC_PROC done, void *arg);
85 
86 /* synchronous function called at shutdown */
87 extern int HPTLIBAPI flush_raid5(PVDevice pArray);
88 
89 extern void HPTLIBAPI raid5_free(_VBUS_ARG PVDevice pArray);
90 
91 struct free_heap_block {
92 	struct free_heap_block *next;
93 };
94 
95 #ifndef LIST_H_INCLUDED
96 struct list_head {
97 	struct list_head *next, *prev;
98 };
99 #endif
100 
101 struct free_page {
102 	struct free_page *link;
103 };
104 
105 struct r5_global_data {
106 	int enable_write_back;
107 	struct list_head inactive_list;
108 	struct list_head dirty_list;
109 	struct list_head active_list;
110 #ifdef R5_CONTIG_CACHE
111 	BUS_ADDR page_base_phys;
112 	PUCHAR page_base_virt;
113 	PUCHAR page_current;
114 #endif
115 	struct free_heap_block *free_heap_slots[10];
116 	struct free_page *free_pages;
117 	UINT num_free_pages;
118 	UINT active_stripes;
119 	UINT num_flushing;
120 	PCommand cache_wait_list;
121 
122 	LBA_T __start[MAX_MEMBERS];
123 	USHORT __sectors[MAX_MEMBERS];
124 };
125 
126 
127 #endif
128